I have discovered a weird problem in my code regarding class constants. While it seems that the code does work correctly, I cannot figure out the reason of PHP Notice I am getting:
Use of undefined constant PAYMENT_ERROR - assumed 'PAYMENT_ERROR' in /src/Micro/Payments/Manager.php on line 146
The code in Manager.php function looks like this:
$code = Result::PAYMENT_ERROR;
return new Result($code, $errMsg); // <- line 146 - causes PHP Notice
What is strange to me, is that $code variable is set correctly and does not trigger any notices. Only instantiating Result does.
The Result class is very simple:
class Result
{
// ... boilerplate code skipped ...
// constant is defined like this:
const PAYMENT_ERROR = 2;
public function __construct($code, array $messages)
{
$this->code = $code;
$this->messages = $messages;
}
// ... other functions skipped as they are not relevat ...
}
Is there a problem that I pass Result's constant to it's own constructor?
Result::PAYMENT_ERROR. It is not possible that the use of$codetriggers this notice. Which makes it likely you're looking at the wrong file or have other issues identifying the correct piece of source code.die(var_dump($code));after assigning$codeand the$codeoutputs correct value for $code (taken from Result::PAYMENT_ERROR constant), and does NOT show notice. So the error is indeed caused byreturn new Result($code, $errMsg);. Thanks for feedback though. This is also the reason why I added$codein general, as I was previously instantiating result by passing constant directly, not via$code. But that also throw's same Notice, thus I posted here.