Why in the below simplified Plugins system example, passing by reference ($data) is not working ($content is not modified)?
class Plugins
{
public static function runhook()
{
$args = func_get_args();
$hook = array_shift($args);
foreach ($args as &$a); // be able to pass $args by reference
call_user_func_array(array('Plugin', $hook), $args);
}
}
class Plugin
{
public static function modifData(&$data)
{
$data = 'Modified! :'.$data;
}
}
class Application
{
public $content;
public function __construct()
{
$this->content = 'Content from application...';
}
public function test()
{
echo $this->content; // return 'Content from application...'
Plugins::runHoook('modifData', $this->content);
echo $this->content; // return 'Content from application...' instead of 'Modified! :Content from application...'
}
}
$app = new Application();
$app->test();
As you can see $this->content should be modified by the modifData() called in background by runHook() function of the Plugin class. But for a strange reason nothing expected happens and the variable stay stuck in his original state... Maybe I'm wrong?
Thanks in advance for any help...