php5 i call_user_func oraz call_user_method_array |
php5 i call_user_func oraz call_user_method_array |
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] |
|
|
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. |
|
|
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... |
|
|
Wersja Lo-Fi | Aktualny czas: 27.09.2024 - 02:58 |