Bug #75562 [Com]: token_get_all() errors should be catchable

From: Date: Thu, 23 Nov 2017 18:04:43 +0000
Subject: Bug #75562 [Com]: token_get_all() errors should be catchable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212704@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75562&edit=1

 ID:                 75562
 Comment by:         spam2 at rhsoft dot net
 Reported by:        software at nano dot net dot tr
 Summary:            token_get_all() errors should be catchable
 Status:             Not a bug
 Type:               Bug
 Package:            Reproducible crash
 Operating System:   Ubuntu 16.04.3 LTS
 PHP Version:        7.1.11
 Block user comment: N
 Private report:     N

 New Comment:

the big change in PHP7 is that you can catch *everyting* with catch(Throwable $exception)

http://php.net/manual/en/migration70.incompatible.php

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.

http://php.net/manual/en/class.parseerror.php


Previous Comments:
------------------------------------------------------------------------
[2017-11-23 17:47:19] 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 16:50:59] nikic@php.net

token_get_all() errors are catchable using catch(ParseError $e).

------------------------------------------------------------------------
[2017-11-23 15:58:41] software at nano dot net dot tr

Description:
------------
OS is Ubuntu 16.04.3 LTS
PHP package is 7.1.11-1+ubuntu16.04.1+deb.sury.org+1 installed from http://ppa.launchpad.net/ondrej/php/ubuntu

While using token_get_all() with TOKEN_PARSE flag; if tested code block has syntax error, then
process killed with "Parse error: syntax error".
Example: https://3v4l.org/05lUI




Test script:
---------------
<?php
// 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)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=75562&edit=1


Thread (4 messages)

« previous php.bugs (#212704) next »