php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37915 __FUNCTION__ does not work inside create_function
Submitted: 2006-06-26 11:56 UTC Modified: 2006-06-26 12:07 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: jexus at jexus dot net Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jexus at jexus dot net
New email:
PHP Version: OS:

 

 [2006-06-26 11:56 UTC] jexus at jexus dot net
Description:
------------
I was trying to create a recursive function with create_function, but I found a weird problem. When I used the magic constant __FUNCTION__, it returned 'lambda_func', instead of 'lambda_1', the actual result create_function returned.

Reproduce code:
---------------
<?php
$func = create_function (
    '$a',
    'return is_array ($a)' . "\n" .
    '    ? array_map (__FUNCTION__, $a)' . "\n" .
    '    : (is_object ($a)' . "\n" .
    '       ? (object) array_map (__FUNCTION__, (array) $object)' . "\n" .
    '       : (is_string ($a)' . "\n" .
    '           ? htmlspecialchars (str_replace ("\n", \'\n\', $a))' . "\n" .
    '           : $a));'
);

var_dump ($func ('string_var', array ('array_var', 'another_var')));
?>


Expected result:
----------------
array(2) {
  [0]=>
  string(9) "array_var"
  [1]=>
  string(11) "another_var"
}

Actual result:
--------------
Warning: array_map(): The first argument, '__lambda_func', should be either NULL or a valid callback in /home/jexus/public_html/test/test.php(22) : runtime-created function on line 2
NULL 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-26 12:07 UTC] tony2001@php.net
Constant __FUNCTION__ is resolved during compile time, while lambda functions are created in runtime, so the constant value is correct.
I don't think anybody is going to change it ever.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC