I have in laravel inside the same App folder a class and a trait
MyClass.php
<?php
namespace App;
class MyClass {
use myTrait;
CONST MY_CONST = 'CONST';
public function showConst() {
echo $this->myTraitMethod();
}
}
MyTrait.php
<?php
namespace App;
class MyTrait {
public function myTraitMethod() {
return self::MY_CONST; // Undefined class constant 'MY_CONST'
return static::MY_CONST; // Undefined class constant 'MY_CONST'
return MyClass:MY_CONST; // This is the only one that works but I'm forcing the class name
}
}
the issue is that I cannot access MY_CONST except if I force the parent class name that is not a solution for me.
The issue is just with vscode, I mean the code runs fines with both self and static but vscode returns the error
Undefined class constant 'MY_CONST'