This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 267919 - Class constant not recognized when called from instance in object property
Summary: Class constant not recognized when called from instance in object property
Status: RESOLVED DUPLICATE of bug 258527
Alias: None
Product: php
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-07 10:00 UTC by Ninj
Modified: 2016-09-08 09:49 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ninj 2016-09-07 10:00:26 UTC
I found no duplicate.

PHP supports class constants:

    class A
    {
        const CONSTANT = 3;
    }

Can be refered to like this:

    echo A::CONSTANT;

And, just like static properties, class constants can be refered to through an instance of the class:

    $a = new A();
    echo $a::CONSTANT;

This works in Netbeans. But now, let's do the same using properties of an object, instead of simple variables:

    class B
    {
        private $a;

        public function f()
        {
            $this->a = new A();
            $foo = $this->a::CONSTANT; // doesn't work as expected, in PHP, but makes no error in netbeans
            $bar = ($this->a)::CONSTANT // works nicely but raises an error in Netbeans
        }
    }

Hope it's clear enough, but feel free to ask me for more details. I tested in the today's nightly (septembre 7th, 2016)
Comment 1 Tomas Mysik 2016-09-07 11:37:49 UTC
IMO duplicate of #258527.

Thanks for reporting.

*** This bug has been marked as a duplicate of bug 258527 ***
Comment 2 Ninj 2016-09-07 21:52:52 UTC
Indeed it probably has the same technical background but there is an important difference: in my case, using simple variables works fine (NB recognize the constant), but it's underlined as "error", in red, when used like this:

    ($this->field)::CONSTANT
Comment 3 Tomas Mysik 2016-09-08 05:48:45 UTC
(In reply to Ninj from comment #2)
>     ($this->field)::CONSTANT

In such a case, see issue #259111.

Thanks.
Comment 4 Ninj 2016-09-08 09:49:05 UTC
You are right, i didn't find see this one. Thank you.

I can then just hope for a soon fix, but i understand it's harsh.