|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-03-10 18:00 UTC] frase at cs dot wisc dot edu
Description:
------------
If a class definition generates a notice, the line number printed with the notice corresponds to the first line in which the class is instantiated, and NOT the line which truly gives rise to the notice.
Reproduce code:
---------------
class OtherClass {
// etc...
}
class TestClass {
static $linkedClass = OtherClass;
function __construct() {
echo "I am linked to " . self::$linkedClass;
}
}
$obj = new TestClass();
Expected result:
----------------
I am linked to OtherClass
Actual result:
--------------
Notice: Use of undefined constant OtherClass - assumed 'OtherClass' in test.php on line 10
I am linked to OtherClass
Line 10 does not contain the phrase 'OtherClass' to begin with, as an undefined constant or otherwise, so the notice is confusing. The line on which the notice actually arises is line 5, where the class' static member is incorrectly initialized (it should, in fact, have been a string).
Disclaimer: The need to have one class refer to another by name, as in this example, may seem odd but is irrelevant to this bug report (it arose for me because of a more complicated class inheritance need). I suspect any notice arising during a class' static member initialization will have the same wrong line-number; errors other than E_NOTICE might as well, I haven't taken the time to check exhaustively.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 15:00:01 2025 UTC |
The problem here is that the constant is evaluated just in time, which means it will only be looked for when you instantiate the class. Your example may be reduced to : class A { public $a = FOOBAR; } $a = new A; // Error will be triggered at this point. Currently the line at which the constant is actually used is not tracked.