php.net |  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
Votes:4
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
Description:
------------
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
<?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
<?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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-06 01:39 UTC] yohgaki@php.net
-Status: Open +Status: Verified
 [2017-05-19 10:41 UTC] jhabdas at gmail dot com
Appears to be dupe of https://bugs.php.net/bug.php?id=70457
 [2017-05-19 10:57 UTC] requinix@php.net
-Status: Verified +Status: Duplicate -Package: *General Issues +Package: Scripting Engine problem
 [2017-05-19 10:57 UTC] requinix@php.net
Dupe-ing this one because the other has commentary.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 05:01:24 2019 UTC