From: a at b dot c dot de
Operating system: Windows XP
PHP version: 5.1.2
PHP Bug Type: Scripting Engine problem
Bug description: lambda functions unusable in create_function()
Description:
------------
When inserting (the name of) a lambda function provided by create_function
into a string that will be used to create a second lambda function, the
second function fails to parse. The parse error message makes what appears
to be a spurious complaint about the code; only Test 5's error message
makes sense (plus, it seems there is no "callable" version of a lambda
function's name).
(Cf. bug #10721 - parser chokes on lambda function names in eval'd code)
Reproduce code:
---------------
I made five distinct tests to bracket the issue:
TEST 1:
// Creating a function that calls an ordinary function (explict name)
function always_true(){return true;}
$afun = create_function('', 'return !always_true();');
echo "Calling $afun() " . ($afun() ? "returns true\n" : "returns
false\n");
TEST 2:
// Creating a function that calls an ordinary function (variable name)
function always_true(){return true;}
$b1 = 'always_true';
$bfun = create_function('','return !'.$b1.'();');
echo "Calling $bfun() " . ($bfun() ? "returns true\n" : "returns
false\n");
TEST 3:
// Creating a function that calls an anonymous function (explicit name);
$c1 = create_function('','return true;');
$cfun = create_function('','return !'.chr(0).'lambda_3();');
echo "Calling $cfun() " . ($cfun() ? "returns true\n" : "returns
false\n");
TEST 4:
// Creating a function that calls an anonymous function (variable name)
$d1 = create_function('','return true;');
$dfun = create_function('','return !'.$d1.'();');
echo "Calling $dfun() " . ($dfun() ? "returns true\n" : "returns
false\n");
TEST 5:
// Using is_callable to get a callable version of anonymous function name
$e1 = create_function('', 'return true;');
if(!is_callable($e1,false,$callable_e1)) die("Couldn't call anonymous
function.");
echo "Using $callable_e1 as name of anonymous function\n";
$efun = create_function('','return !'.$callable_e1.'();');
echo "Calling $efun() " . ($efun() ? "returns true\n" : "returns
false\n");
Expected result:
----------------
TEST 1:
Calling lambda_1() returns false
TEST 2:
Calling lambda_1() returns false
TEST 3:
Calling lambda_2() returns false
TEST 4:
Calling lambda_2() returns false
TEST 5:
Using lambda_1 as name of anonymous function [?]
Calling lambda_2() returns false
Actual result:
--------------
Actual Results:
TEST 1:
Calling lambda_1() returns false
TEST 2:
Calling lambda_1() returns false
TEST 3:
Parse error: parse error, unexpected '}' in test.php : runtime-created
function on line 1
Fatal error: Function name must be a string in test.php on line 4
TEST 4:
Parse error: parse error, unexpected '}' in test.php : runtime-created
function on line 1
Fatal error: Function name must be a string in test.php on line 4
TEST 5:
Using as name of anonymous function
Parse error: parse error, unexpected ')' in test.php : runtime-created
function on line 1
Fatal error: Function name must be a string in test.php on line 6
--
Edit bug report at http://bugs.php.net/?id=37016&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=37016&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=37016&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=37016&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37016&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=37016&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37016&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37016&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37016&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37016&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37016&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=37016&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=37016&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37016&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37016&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37016&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37016&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37016&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37016&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37016&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37016&r=mysqlcfg