note 83345 deleted from language.constants.predefined by danbrown

From: Date: Wed, 25 Jun 2008 15:59:38 +0000
Subject: note 83345 deleted from language.constants.predefined by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140810@lists.php.net to get a copy of this message
Note Submitter: Michael Spencer ---- With all due respect, David, you don't know what you are talking about. ;) Ivan's point is a valid one, as his single-quoted line, once passed to an eval, is stripped of said quotes and treated as a standard php expression -- or at least it should be. In proper operation, the magic constant ought to work within the eval the same as a variable would, but it doesn't. I've expanded his test to better illustrate what he meant. <?php function eval_test() { echo "User function name: " . __FUNCTION__ . "\n"; eval('echo "in eval(): User function name: " . __FUNCTION__ . "\n";'); } function eval_test_with_variable() { $function = __FUNCTION__; echo "User function name from constant: " . __FUNCTION__ . "\n"; echo "User function name from variable: " . $function . "\n"; eval('echo "in eval(): User function name from constant: " . __FUNCTION__ . "\n";'); eval('echo "in eval(): User function name from variable: " . $function . "\n";'); } echo "\nTest 1: Magic Constant Only\n\n"; eval_test(); echo "\nTest 2: Magic Constant and Variable\n\n"; eval_test_with_variable(); ?> Note the only difference between the tests in eval_test_with_variable() is the replacement of __FUNCTION__ with $function -- still within those single quotes you criticized him on. Result: Test 1: Magic Constant Only User function name: eval_test in eval(): User function name: Test 2: Magic Constant and Variable User function name from constant: eval_test_with_variable User function name from variable: eval_test_with_variable in eval(): User function name from constant: in eval(): User function name from variable: eval_test_with_variable Ivan simply and properly noted that eval() isn't processing magic constants as it ought to.

« previous php.notes (#140810) next »