Have you actually tried something? It's as simple as this:
final class A
{
public static $instance;
public static function get()
{
if (self::$instance === null)
self::$instance = new self();
return self::$instance;
}
public static function b()
{
return array('a','b','c');
}
}
$class = 'A';//class name
$getter = 'get';//static method
$method = 'b';//public method
$instance = $class::getter();//calls A::get()
$array = $instance->{$method}();//gets array
//check with:
var_dump(
$class::$getter()
->{$method}()
);
If you only have this string (A::get()->b()) to go on, you'll have to process/parse that string, and take it from there. A simple, but crude way to do so would be through regex:
$str = 'A::get()->b()';
preg_match_all('/(.+?)(::|\(\)-?>?)/', $str, $matches)
{
$operators = $matches[2];//array('::', '()->', '()')
$operands = $matches[1];//array('A', 'get', 'b');
$result = null;
for ($i=0, $j=count($operands);$i<$j;++$i)
{
$result = $operands[$i];//
switch ($operator[$i])
{
case '::':
$member = $operand[++$i];//next operand
if (substr($opertator[$i],0,2) === '()')
$result = $result::$member();
else
$result = $result::{$member};//static property
break;
case '()->'://non-static access
case '()':
$result = $result->{$operand[$i]}();
break;
default:
$result = $result->{$operand[$i]};//non-static property
}
}
}
Note that this is un-tested, and very rough around the edges, but it should be enough to get you started.
eval(), but you are doing it seriously wrong if you need to do what you want. Why do you need to call that string?eval