<?php
class Test {
protected $url;
public function __construct(string $url = null) {
$this->url = $url;
}
public function url() : string {
return $this->url;
}
}
$test = new Test(null);
echo $test->url();
Fatal error: Uncaught TypeError: Test::url(): Return value must be of type string, null returned in /in/WVrvU:10
Stack trace:
#0 /in/WVrvU(16): Test->url()
#1 {main}
thrown in /in/WVrvU on line 10
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: Test::url(): Return value must be of type string, null returned in /in/WVrvU:10
Stack trace:
#0 /in/WVrvU(16): Test->url()
#1 {main}
thrown in /in/WVrvU on line 10
Process exited with code 255.
Fatal error: Uncaught TypeError: Return value of Test::url() must be of the type string, null returned in /in/WVrvU:10
Stack trace:
#0 /in/WVrvU(16): Test->url()
#1 {main}
thrown in /in/WVrvU on line 10
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/WVrvU on line 9
Process exited with code 255.