ID: 37016
Comment by: a dot steenveld at id dot umcn dot nl
Reported By: a at b dot c dot de
Status: Assigned
Bug Type: Scripting Engine problem
Operating System: Windows XP
PHP Version: 5.1.2
Assigned To: derick
New Comment:
hmmm.... I've not done enough reseachr in the bugreports. Well, I did,
but too late. :(
While looking for a similar problem I found a likely cause for this
problem, found a workaround for my problem, and suggested a change and
filed a bug report.
See report #40160, hope you can use it.
Previous Comments:
------------------------------------------------------------------------
[2006-04-08 11:51:18] [EMAIL PROTECTED]
I can reproduce this... let's see if I can come up with a fix.
------------------------------------------------------------------------
[2006-04-08 05:35:12] a at b dot c dot de
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 this bug report at http://bugs.php.net/?id=37016&edit=1