Bug #68026 [Nab]: create_function() fails

From: Date: Tue, 16 Sep 2014 17:27:18 +0000
Subject: Bug #68026 [Nab]: create_function() fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187551@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68026&edit=1 ID: 68026 Updated by: requinix@php.net Reported by: jmichae3 at yahoo dot com Summary: create_function() fails Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Windows 7 pro x64 sp1 PHP Version: 5.5.16 Block user comment: N Private report: N New Comment: >The $isadminfile variable contains a function. Well, technically it contains a function name, not a closure. Previous Comments: ------------------------------------------------------------------------ [2014-09-16 17:26:00] requinix@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. You have not defined a function named "isadminfile". The $isadminfile variable contains a function. So in code where you want to use them you'd have to do global $isadminfile; $return = $isadminfile($filepath); Your code to test function creation should be !is_callable(${'is'.$AcctTypes[$i].'file'}) But please, do a favor for everyone who has to deal with your code: 1. Stop using globals 2. Don't use variable variables 3. Don't dynamically create important functions ------------------------------------------------------------------------ [2014-09-16 09:26:14] jmichae3 at yahoo dot com Description: ------------ create_function doesn't seem to actually create the function. Test script: --------------- $AcctTypes=preg_split('/,/', 'admin,paidbls,paidmusic,user'); for ($i=0; $i < count($AcctTypes); $i++) { global ${'is'.$AcctTypes[$i].'file'}; $funcbody='{ global $AcctTypes;'; $funcbody.=" if (strpos(\$filepath,\"/".$AcctTypes[$i]."/\") !== FALSE"; $funcbody.=" && strpos(\$filepath,\"/".$AcctTypes[$i]."/\") !== ''"; $funcbody.=" && strpos(\$filepath,\"/".$AcctTypes[$i]."/\") <=3) {"; $funcbody.=' return TRUE;'; $funcbody.=' } else {'; $funcbody.=' return FALSE;'; $funcbody.=' } }'; //create the function from the function body in $funcbody with name in $funcname ${'is'.$AcctTypes[$i].'file'}=create_function('$filepath', $funcbody); } for ($i=0; $i < count($AcctTypes); $i++) { if (!function_exists('is'.$AcctTypes[$i].'file')) { die("\n\nERROR:config file needs function ".'is'.$AcctTypes[$i].'file'."()\n\n"); } } Expected result: ---------------- functions created, no output. Actual result: -------------- ( my error when function not defined) ERROR:config file needs function isadminfile() ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68026&edit=1

« previous php.bugs (#187551) next »