zanphp / autoload
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- php: >=5.6
- composer-plugin-api: 1.1.0
This package is not auto-updated.
Last update: 2025-03-30 06:44:30 UTC
README
composer 插件, 模拟静态初值化
<?php interface StaticInitializer { public static function __static(); }
!! 注意,静态初值化的须类必须经过composer加载.
类加载时, public static function __static()
方法会自动执行, 必须无参数, 必须为静态方法
自行require、include功能失效;
使用
composer.json 引入 zanphp/autoload package
{ "require": { "zanphp/autoload": "dev-master" } }
可选接口实现
<?php namespace ZanPHP\Autoload\Tests; class StaticTest { public static function __static() { echo __CLASS__ . " initialized\n"; } }
或者显示实现接口;
<?php namespace ZanPHP\Autoload\Tests; use Composer\Autoload\StaticInitializer; class StaticInterfaceTest implements StaticInitializer { public static function __static() { echo __CLASS__ . " initialized\n"; } }
test
<?php require __DIR__ . "/vendor/autoload.php"; class_exists(\ZanPHP\Autoload\Tests\StaticTest::class, true); class_exists(\ZanPHP\Autoload\Tests\StaticInterfaceTest::class, true);
output
ZanPHP\Autoload\Tests\StaticTest initialized
ZanPHP\Autoload\Tests\StaticInterfaceTest initialized