|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67007 Incorrect (inaccurate) PHP Notice regarding the use of constants
Submitted: 2014-04-02 11:38 UTC Modified: 2017-05-19 10:57 UTC
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:3 (75.0%)
From: edvinas at pnd dot io Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.5.10 OS: Linux
Private report: No CVE-ID: None
 [2014-04-02 11:38 UTC] edvinas at pnd dot io
PHP provides inaccurate NOTICE message regarding constants on class initialization. When you initialize new class, the error message does not point the line in the class which causes said error message, but points to a line where Class is initialized instead.

Test script:
// Foo.php
class Foo { 

    const BAR = 1;
    protected $message = BAR; // <- this line is intentionally incorrect

    public function __construct($message) {
        $this->message = $message;
        echo "Initialized with {$this->message}";

// test.php
include 'Foo.php';
$var = new Foo(Foo::BAR);

Expected result:
Expected result:
Notice: Use of undefined constant BAR - assumed 'BAR' in Foo.php on line 5

Actual result:
Actual result:
Notice: Use of undefined constant BAR - assumed 'BAR' in test.php on line 3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-06 01:39 UTC]
-Status: Open +Status: Verified
 [2017-05-19 10:41 UTC] jhabdas at gmail dot com
Appears to be dupe of
 [2017-05-19 10:57 UTC]
-Status: Verified +Status: Duplicate -Package: *General Issues +Package: Scripting Engine problem
 [2017-05-19 10:57 UTC]
Dupe-ing this one because the other has commentary.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 21:01:29 2024 UTC