|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75562 token_get_all() errors should be catchable
Submitted: 2017-11-23 15:58 UTC Modified: 2017-11-23 16:50 UTC
From: software at nano dot net dot tr Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 7.1.11 OS: Ubuntu 16.04.3 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: software at nano dot net dot tr
New email:
PHP Version: OS:


 [2017-11-23 15:58 UTC] software at nano dot net dot tr
OS is Ubuntu 16.04.3 LTS
PHP package is installed from

While using token_get_all() with TOKEN_PARSE flag; if tested code block has syntax error, then process killed with "Parse error: syntax error".

Test script:
// Syntax error: tested code has a space between equal signs
$tokens=token_get_all('<?php if($foo= =$bar) {}', TOKEN_PARSE);
var_dump($tokens); // not printed on error

Expected result:
function returns (FALSE) or throws a catchable error. script continues to run. error could be checked/catched with if, try-catch or error handler.

Actual result:
script dies with error: (Parse error: syntax error, unexpected '=' in  on line 1)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-23 16:50 UTC]
-Status: Open +Status: Not a bug
 [2017-11-23 16:50 UTC]
token_get_all() errors are catchable using catch(ParseError $e).
 [2017-11-23 17:47 UTC] software at nano dot net dot tr
Thanks for information.

There is not anything in manual about this behaviour.

For example in EVAL manual it writes;
"...As of PHP 7, if there is a parse error in the evaluated code, eval() throws a ParseError exception..."

Is it possible to add something like this to token_get_all manual page too?
 [2017-11-23 18:04 UTC] spam2 at rhsoft dot net
the big change in PHP7 is that you can catch *everyting* with catch(Throwable $exception)

Parse errors throw ParseError
Parser errors now throw a ParseError object. Error handling for eval() should now include a catch block that can handle this error.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jun 13 03:01:24 2021 UTC