Description
The following code:
<?php
class Example extends \Exception {
protected $code = 5;
}
echo ' → ', (new Example(''))->getCode(), \PHP_EOL;
echo '0 → ', (new Example('', 0))->getCode(), \PHP_EOL;
echo '1 → ', (new Example('', 1))->getCode(), \PHP_EOL;
Resulted in this output:
But I expected this output instead:
There is a note about default parameters in exception constructor on php.net. However, case 2 in the above example explicitly passes the code parameter to the constructor.
Calling the constructor of class Exception from a subclass ignores the default arguments, if the properties $code and $message are already set. about default parameters in exception constructor on php.net.
PHP Version
PHP 8.2
Operating System
Debian 11
Description
The following code:
Resulted in this output:
But I expected this output instead:
There is a note about default parameters in exception constructor on php.net. However, case 2 in the above example explicitly passes the code parameter to the constructor.
PHP Version
PHP 8.2
Operating System
Debian 11