Bug #70457 [Ver]: Wrong line number for E_NOTICE - undefined constant in class

From: Date: Mon, 26 Mar 2018 10:07:22 +0000
Subject: Bug #70457 [Ver]: Wrong line number for E_NOTICE - undefined constant in class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214482@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70457&edit=1 ID: 70457 Updated by: nikic@php.net Reported by: daniel dot jaenecke at sedo dot com Summary: Wrong line number for E_NOTICE - undefined constant in class Status: Verified Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: Any Block user comment: N Private report: N New Comment: Nowadays delayed constants store an AST, which contains the necessary line number information. This is still not entirely simple, as we also need a) the file name (which is available on the parent class / function, but not inside update_constant) and b) an ability to override the source of an error (something like CG(zend_lineno), but for runtime use). Previous Comments: ------------------------------------------------------------------------ [2018-03-26 09:41:04] yohgaki@php.net https://3v4l.org/ULp0K It happens with static var. Error line is meaningless, since "undefined constant error" is raised for "other" static var. It can hide "undefined constant error" with static class until code access to static var. See 3v4l result for details. ------------------------------------------------------------------------ [2015-09-08 13:54:29] bwoebi@php.net We currently aren't storing any line number information for class variables/constants. And as these are only evaluated upon first use, the constant message will only appear on instantiation here. ------------------------------------------------------------------------ [2015-09-08 09:20:33] yohgaki@php.net https://3v4l.org/DpCPp PHP has been emitting the error like this for a long time. ------------------------------------------------------------------------ [2015-09-08 08:46:58] daniel dot jaenecke at sedo dot com Description: ------------ A notice complaining about an undefined constant assigned to a class property is reported for the wrong line number. I could reproduce this with the provided snippet for versions 5.3, 5.5 and 5.6 Test script: --------------- <?php class MyClass { private $var1 = ANOTHER_NONE_EXISTING_CONSTANT; private $var2 = 1; } $obj = new MyClass(); Expected result: ---------------- A notice for the line where the undefined constant is being used, in this case Notice: Use of undefined constant NONE_EXISTING_GLOBAL_CONSTANT […] in line 6 Actual result: -------------- Notice: Use of undefined constant ANOTHER_NONE_EXISTING_CONSTANT - assumed 'ANOTHER_NONE_EXISTING_CONSTANT' in /home/daniel/tmp/php-linenumber-bug/code.php on line 11 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70457&edit=1

« previous php.bugs (#214482) next »