Próbowałem soebie rozwinąć kod podany przezemnie tutaj ale okazało sie że z powyższymi funkcjami jest problem w php5[php:1:80bef04806]<?php
class Module
{
private static $myReference = array();
public function &getReference($class,$f = null,$s = null,$t = null)
{
if(!isset(self::$myReference[$class]))
self::$myReference[$class] = new $class;
return self::$myReference[$class];
}
}
class User
{
// Zmienne odpowiadające za różne dane z formularza logowania
public $login;
public function __construct()
{
$this->login = "Foo";
}
public function test($f,$s,$t)
{
echo 'sprawdza';
$this->liczby = "liczby: ".$f.", ".$s.", ".$t.".";
}
}
$normal = Module::getReference('user');
$normal->test='ok';
$singleton = Module::getReference('user');
?>
<pre>
<?php
var_dump($normal);
var_dump($singleton);
$test = call_user_method_array('test',$singleton,array('1','2','6'));
// php4 działa php5 nie
// Notice: call_user_method_array() [function.call-user-method-array]: This function is deprecated, use the call_user_func variety with the array(&$obj, "method") syntax instead
$test = call_user_func(array($singleton, "method"),'1','2','6');
// zgodnie z powyższym błędem
// Warning: call_user_func(User::method) [function.call-user-func]: First argument is expected to be a valid callback
$test = call_user_func(array('User', 'test'),'1','2','6');
// czyli zgodnie z php4 i manual'em
// Fatal error: Using $this when not in object context
// i wskazuje -> $this->liczby = "liczby: ".$f.", ".$s.", ".$t.".";
var_dump($test);
?>
</pre>
?>[/php:1:80bef04806]