Thread: eval() issue
View Single Post
Old 11-29-2011, 06:10 PM   #9 (permalink)
wGEric
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

Quote:
Originally Posted by Parkinson4 View Post
My favourite trick involving dynamic evaluation enables static calls on variable classes. Since $foo::bar() is illegal in PHP, below solution works around that limitation.
PHP 5.3 lets you do that

I tend to find that those that use eval don't know the language well enough to do it any other way. There are very few cases to use eval. Your example can be done with the following code:

PHP Code:
<?php

class Foo {
    public static function 
bar() {
        return 
'bar';
    }
}

$foo 'Foo';

$result1 call_user_func_array($foo '::bar', array());
echo 
$result1;

$result2 call_user_func_array(array($foo'bar'), array());
echo 
$result2;

// $result3 = $foo::bar(); works in PHP 5.3
// echo $result3;
__________________
Eric
wGEric is offline  
Reply With Quote