79184310

Date: 2024-11-13 09:57:02
Score: 0.5
Natty:
Report link

So after I understood that the issue was just in vscode, I found that is a know issue of Intelephense due the fact that in older php versions, constants could not be declared in php traits

https://github.com/bmewburn/vscode-intelephense/issues/2024

the solution is to suppress the message using /** @disregard P1012 */ on top like this

MyTrait.php

<?php

namespace App;

class MyTrait {
    
    public function myTraitMethod() {
        /** @disregard P1012 */
        return self::MY_CONST;
    }
}
Reasons:
  • Whitelisted phrase (-1): solution is
  • Has code block (-0.5):
  • User mentioned (1): @disregard
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: silvered.dragon