I have folder with many plugins. Each plugin contains same name class but different content:
plugin01.php
class Plugin{
public function get($a){
return 'Plugin01 - '.$a;
}
}
plugin02.php
class Plugin{
public function get($a){
return 'Plugin02 - '.$a;
}
}
In Plugins.php, i want to load this plugins. But not only once.
class Plugins{
public static function load($id){
require $id.'.php';
$plugin = new Plugin();
return $plugin->get('test');
}
}
echo Plugins::load('plugin01')."\n";
echo Plugins::load('plugin02')."\n";
echo Plugins::load('plugin01');
Expected result:
Plugin01 - test
Plugin02 - test
Plugin01 - test
Current Result:
Fatal error: Cannot redeclare class Plugin
This definitely does not work, because i am redefining
class name and including
more times same plugin.
My question is, can I include file only in Function scope (including all classes defined in external file), that if will not appear outside function?
Can I do that with PHP, or must I use different names for each class?