note 83345 added to language.constants.predefined

From: Date: Wed, 21 May 2008 16:53:16 +0000
Subject: note 83345 added to language.constants.predefined
Groups: php.notes 
Request: Send a blank email to php-notes+get-139590@lists.php.net to get a copy of this message
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. ---- Server IP: 208.69.120.35 Probable Submitter: 24.176.228.76 ---- Manual Page -- http://www.php.net/manual/en/language.constants.predefined.php Edit -- https://master.php.net/note/edit/83345 Del: integrated -- https://master.php.net/note/delete/83345/integrated Del: useless -- https://master.php.net/note/delete/83345/useless Del: bad code -- https://master.php.net/note/delete/83345/bad+code Del: spam -- https://master.php.net/note/delete/83345/spam Del: non-english -- https://master.php.net/note/delete/83345/non-english Del: in docs -- https://master.php.net/note/delete/83345/in+docs Del: other reasons-- https://master.php.net/note/delete/83345 Reject -- https://master.php.net/note/reject/83345 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139590) next »