<?php
abstract class x {
function test($z, x $x)
{
var_dump($x);
}
}
class y extends x {
function test($z, $x = null)
{
parent::test($x, $x);
}
}
(new y)->test(null);
Fatal error: Uncaught TypeError: x::test(): Argument #2 ($x) must be of type x, null given, called in /in/45tDp on line 13 and defined in /in/45tDp:4
Stack trace:
#0 /in/45tDp(13): x->test(NULL, NULL)
#1 /in/45tDp(17): y->test(NULL)
#2 {main}
thrown in /in/45tDp on line 4
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Fatal error: Uncaught TypeError: x::test(): Argument #2 ($x) must be of type x, null given, called in /in/45tDp on line 13 and defined in /in/45tDp:4
Stack trace:
#0 /in/45tDp(13): x->test(NULL, NULL)
#1 /in/45tDp(17): y->test(NULL)
#2 {main}
thrown in /in/45tDp on line 4
Process exited with code 255.
Fatal error: Uncaught TypeError: Argument 2 passed to x::test() must be an instance of x, null given, called in /in/45tDp on line 13 and defined in /in/45tDp:4
Stack trace:
#0 /in/45tDp(13): x->test(NULL, NULL)
#1 /in/45tDp(17): y->test(NULL)
#2 {main}
thrown in /in/45tDp on line 4
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33
Warning: Declaration of y::test($z, $x = NULL) should be compatible with x::test($z, x $x) in /in/45tDp on line 15
Fatal error: Uncaught TypeError: Argument 2 passed to x::test() must be an instance of x, null given, called in /in/45tDp on line 13 and defined in /in/45tDp:4
Stack trace:
#0 /in/45tDp(13): x->test(NULL, NULL)
#1 /in/45tDp(17): y->test(NULL)
#2 {main}
thrown in /in/45tDp on line 4
Process exited with code 255.
Strict Standards: Declaration of y::test() should be compatible with x::test($z, x $x) in /in/45tDp on line 15
Catchable fatal error: Argument 2 passed to x::test() must be an instance of x, null given, called in /in/45tDp on line 13 and defined in /in/45tDp on line 4
Process exited with code 255.