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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: edvinas at pnd dot io
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC