Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> php5 i call_user_func oraz call_user_method_array
Bora
post 22.04.2004, 11:37:10
Post #1





Grupa: Zarejestrowani
Postów: 270
Pomógł: 0
Dołączył: 15.06.2003

Ostrzeżenie: (0%)
-----


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]
Go to the top of the page
+Quote Post
Ozzy
post 22.04.2004, 19:45:04
Post #2





Grupa: Zarejestrowani
Postów: 204
Pomógł: 0
Dołączył: 26.12.2003
Skąd: Rzeszów

Ostrzeżenie: (0%)
-----


Ja to rozwiązałem w sposób opisany w http://forum.php.pl/viewtopic.php?t=13770&...er=asc&start=45
Nie używam już tego kodu, ale wtedy rozwiązywało to problem z argumentami.
Go to the top of the page
+Quote Post
hawk
post 22.04.2004, 21:41:50
Post #3





Grupa: Zarejestrowani
Postów: 521
Pomógł: 0
Dołączył: 3.11.2003
Skąd: 3city

Ostrzeżenie: (0%)
-----


Cytat
[php:1:c0a422bde3]<?php
$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
?>[/php:1:c0a422bde3]

Przecież metody "method" nie ma...
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 29.03.2024 - 11:03