how about using:
return call_user_func(array($object1, 'do_static'));
I've also modified your code so it works with both an object and a class:
<?php
class Class1 {
static function do_static() {
echo 'ok';
}
}
function use_static($object1) {
if(is_object($object1)) {
$class = get_class($object1);
} else {
$class = $object1;
}
return call_user_func(array($class, 'do_static'));
}
use_static('Class1');
$obj = new Class1;
use_static($obj);
?>
Adrian Cid Almaguer wrote:
Hi:
I had the fallowing trouble while using a static method call on php5. Here's
my solution, i will really apreciate if anyone else can find another way
around..
The problem:
I have a fuction wich get a parameter that's an objetc, and that objetc
belongs to a class wich has a static method ( several class's may have the
same method, that's the reason for i never know for sure wich class the
objetc belongs to...) it has to be call inside the fuction... the solution i
found was:
<?
class Class1 {
static function do_static() { echo 'ok'; }
}
function use_static($object1) {
$class1 = get_class($object1);
$method = new ReflectionMethod($class1, 'do_static');
$method->invoke(null);
// First, I thinks do that
// $class1 = get_class($object1);
// $class1::do_static;
// But, I recieve an error
}
$object1 = new Class1;
use_static($object1);
?>
gretings
Adrian
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php