From:             a dot steenveld at id dot umcn dot nl
Operating system: MS windows XP pro
PHP version:      4.4.4
PHP Bug Type:     Feature/Change Request
Bug description:  create_function() result name starts with a '\0'. Request to 
chang to e.g. '1'

Description:
------------
create_function() results gets lost sometimes.
And yes, I've checked preveous bugreports, and yes, I know that the use of
create_function() is advised againt in the way I'm using it here. But I
wan't to use continuations in PHP.

The problem is akin to bug 10721 (which is not a bug).

The problem:
create_function() returns a string in the format '\0lambda_%d'
Subsequent calls with a result from create_function() as a argument will
result in an empy string.
           
The workaround is to remove (or replace) this 0.

Request to change the result from create_function().
Starting the name with a digit (or any character not in [_A-Za-z]) will
result in an illegal name, safe enough to prevent name clashes.
This suggest a format like '%d_lambda' as return result from
create_function().

Reproduce code:
---------------
<?php
/* cont.php   -   problem with continuations when using create_function()
   vim:nu

   Code inspired by
http://www.ps.uni-sb.de/~duchier/python/continuations.html
*/

function writeln($s) { echo "$s\n"; }

function lambda  ($args, $code) { return        create_function ($args,
$code);     }
function lambda0 ($args, $code) { return substr(create_function ($args,
$code), 1); }
function L ($l) { if (strncmp($l, 'lambda_', 7) === 0) return "\0$l"; else
return $l; }
        
function mul ($x, $y, $c) { echo "mul($x, $y, $c)\n"; $f = L($c);
$f($x*$y); }
function add ($x, $y, $c) { echo "add($x, $y, $c)\n"; $f = L($c);
$f($x+$y); }
function mal ($x, $y, $c) { echo "mal($x, $y, $c)\n"; mul(2, $x, lambda0
('$v', "add(\$v, $y, $c);")); }
function ma  ($x, $y, $c) { echo "ma($x, $y, $c)\n";  $f = L($c);
$f(2*$x+$y); }

function f_OK   ($x, $y) { mal($x, $y, lambda0 ('$v', "writeln(\"f($x, $y)
= \$v\");")); } 
function f_FAIL ($x, $y) { mal($x, $y, lambda  ('$v', "writeln(\"f($x, $y)
= \$v\");")); } 

        f_OK  (2, 2);
        f_FAIL(2, 2); // the result of create_function() gets truncated to an
empty string! 
?>

Expected result:
----------------
// f_FAIL)() not active
mal(2, 2, lambda_1) 
mul(2, 2, lambda_2) 
add(4, 2, lambda_1) 
f(2, 2) = 6

Actual result:
--------------
// f_FAIL)() active
mal(2, 2, lambda_1) 
mul(2, 2, lambda_2) 
add(4, 2, lambda_1) 
f(2, 2) = 6 
mal(2, 2, \0lambda_3)
Parse error:  parse error, unexpected '}' in ...\cont.php(11) :
runtime-created function on line 1
mul(2, 2, )
Fatal error:  Call to undefined function:  () in ...\cont.php on line 14

-- 
Edit bug report at http://bugs.php.net/?id=40160&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=40160&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=40160&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=40160&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40160&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=40160&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40160&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40160&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40160&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40160&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40160&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=40160&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=40160&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40160&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40160&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40160&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40160&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40160&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40160&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40160&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40160&r=mysqlcfg

Reply via email to