Bug->Doc #70929 [Nab->Opn]: create_function now throws ParseError

From: Date: Tue, 17 Nov 2015 19:01:53 +0000
Subject: Bug->Doc #70929 [Nab->Opn]: create_function now throws ParseError
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12868@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70929&edit=1 ID: 70929 Updated by: bishop@php.net Reported by: bishop@php.net -Summary: create_function regression when parse error present +Summary: create_function now throws ParseError -Status: Not a bug +Status: Open -Type: Bug +Type: Documentation Problem -Package: Scripting Engine problem +Package: Documentation problem PHP Version: 7.0Git-2015-11-17 (Git) Block user comment: N Private report: N New Comment: 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. :) Previous Comments: ------------------------------------------------------------------------ [2015-11-17 18:54:22] nikic@php.net You have to catch ParseError (or Error, or Throwable), not Exception: https://3v4l.org/4MOJt ------------------------------------------------------------------------ [2015-11-17 18:40:04] bishop@php.net The following patch has been added/updated: Patch Name: capture_parse_exceptions Revision: 1447785604 URL: https://bugs.php.net/patch-display.php?bug=70929&patch=capture_parse_exceptions&revision=1447785604 ------------------------------------------------------------------------ [2015-11-17 18:39:12] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70929&edit=1

« previous php.doc.bugs (#12868) next »