|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-11-17 18:39 UTC] bishop@php.net
Description: ------------ In PHP versions 5.3.19 - 5.6.15, a parse error in create_function returns false, per the manual: > If there is a parse error in the evaluated code, eval() returns FALSE and > execution of the following code continues normally. As of PHP 7, this outputs only a parse error and terminates the script. See https://3v4l.org/apEOR#v5319 Test script: --------------- <?php $a = create_function('', 'return (return;);'); var_dump($a, 'here'); Expected result: ---------------- Parse error: syntax error, unexpected 'return' (T_RETURN) in %s : runtime-created function on line %d bool(false) string(4) "here" Actual result: -------------- Parse error: syntax error, unexpected 'return' (T_RETURN) in %s : runtime-created function on line %d Patchescapture_parse_exceptions (last revision 2015-11-17 18:40 UTC by bishop@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 02:00:01 2025 UTC |
As of PHP 7, create_function now throws an exception when there's an internal parse error: try { $result = create_function('', 'return (return 1);'); } catch (ParseError $ex) { $result = $ex->getMessage(); } https://3v4l.org/oCHLh#v700alpha2 The docs should be updated to reflect this. --- Thanks @nikic, was just about to say that. :)