I have a variable $className which is name of declared class in php and I want
- create an object of this class
- lunch a static method of this class
I have a variable $className which is name of declared class in php and I want
There's also the Reflection API. E.g.:
<?php
$rc = new ReflectionClass('A');
// question 1) create an instance of A
$someArgs = array(1,2,3);
$obj = $rc->newInstanceArgs($someArgs);
// question 2) invoke static method of class A
$rm = $rc->getMethod('foo');
if ( !$rm->isStatic() ) {
echo 'not a static method';
}
else {
$rm->invokeArgs(null, $someArgs);
}
class A {
public function __construct($a, $b, $c) { echo "__construct($a,$b,$c)\n";}
public static function foo($a, $b, $c) { echo "foo($a,$b,$c)\n";}
}