Bug #71620 [Opn]: strange behavour of parser and exception's handler
| From: | requinix@php.net | Date: | Wed, 17 Feb 2016 21:47:49 +0000 |
| Subject: | Bug #71620 [Opn]: strange behavour of parser and exception's handler | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199309@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71620&edit=1
ID: 71620
Updated by: requinix@php.net
Reported by: miracle at rpz dot name
Summary: strange behavour of parser and exception's handler
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.0.3
Block user comment: N
Private report: N
New Comment:
https://3v4l.org/K4KhS
The deprecated constructor problem is being detected at compile time - before any code has been
executed. You can test this by return;ing at the very beginning of the file. https://3v4l.org/tL7G2
By throwing the exception, the file is not executed at all and thus the constant will not be
define()d.
The same problem exists if you use a variable: https://3v4l.org/oQlFm
With that said, given that the class exists, I would expect const to work too. (Or neither.) But it
does not: https://3v4l.org/h02r8
Additionally, wrapping the class definition in an if(true) causes both the class and constant to be
undefined, which is what I would have expected from the original code: https://3v4l.org/QdWiC
Previous Comments:
------------------------------------------------------------------------
[2016-02-17 21:11:50] miracle at rpz dot name
Description:
------------
Legacy code use PEAR's classes with php4-style constructor. Usualy In same file defined several
global constants used in class. When this file included, then engine throw warning about deprecated
constructor. After catch this "exception" we have new class (hooray!) and undefined
constants from same file...
Test script:
---------------
foo.php:
<?php
define('LOST_CONSTANT', 42);
class Foo {
public function foo() {
// throw notice about deprecated constructor
}
}
?>
main.php:
<?php
set_error_handler(function($errno, $errstr) {
throw new Exception($errstr, $errno); // convert error to exception
});
try {
include 'foo.php';
} catch (Exception $e) {
printf("error %d with message: %s\n", $e->getCode(), $e->getMessage());
}
var_dump(
class_exists('foo'), // exists!
defined('LOST_CONSTANT') // where is my constant
);
Expected result:
----------------
error 8192 with message: Methods with the same name as their class will not be constructors in a
future version of PHP; Foo has a deprecated constructor
main.php:14:
bool(true)
main.php:14:
bool(true)
Actual result:
--------------
error 8192 with message: Methods with the same name as their class will not be constructors in a
future version of PHP; Foo has a deprecated constructor
main.php:14:
bool(true)
main.php:14:
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71620&edit=1