bmewburn / intelephense-docs

Documentation for the Intelephense PHP language server
https://intelephense.com
Other
184 stars 17 forks source link

Constants not recognized as static or self in Traits #57

Closed nd4c closed 1 year ago

nd4c commented 1 year ago

Intelephense flags reference in a trait to a local const as an error. The const has to be in the "using" class since trait do not support constants.

I am using the "free" version. I do not know if is an error in the licensed version.

<?php
namespace app\validnamespace;

/**
 * this trait is used in SomeUsefulClass which has a public const NOTFOUND = 'Not found';
 *//
trait SomeUsefulTrait
{
    public function someUsefulMethod(): string
    {
        // this will _not_ pass intelephense
        $var = static::NOTFOUND;

        // this will _not_ pass intelephense
        $var = self::NOTFOUND;

        // this _will_ pass intelephense
        $var = SomeUsefulClass::NOTFOUND;
        return $var;
    }
}
nd4c commented 1 year ago

My bad - this was supposed to be in the code issues, not the docs issues.