<?php
class Address
{
public $street;
}
class User
{
public function getAddress() : Address
{
return $this->address;
}
}
$user = new User();
$address = $user->getAddress();
var_dump($address->street);
Warning: Undefined property: User::$address in /in/VNK5B on line 10
Fatal error: Uncaught TypeError: User::getAddress(): Return value must be of type Address, null returned in /in/VNK5B:10
Stack trace:
#0 /in/VNK5B(15): User->getAddress()
#1 {main}
thrown in /in/VNK5B on line 10
Process exited with code 255.
Notice: Undefined property: User::$address in /in/VNK5B on line 10
Fatal error: Uncaught TypeError: Return value of User::getAddress() must be an instance of Address, null returned in /in/VNK5B:10
Stack trace:
#0 /in/VNK5B(15): User->getAddress()
#1 {main}
thrown in /in/VNK5B on line 10
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught TypeError: Return value of User::getAddress() must be an instance of Address, null returned in /in/VNK5B:10
Stack trace:
#0 /in/VNK5B(15): User->getAddress()
#1 {main}
thrown in /in/VNK5B on line 10
Process exited with code 255.
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/VNK5B on line 8
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':', expecting '{' or ';' in /in/VNK5B on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VNK5B on line 4
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VNK5B on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/VNK5B on line 4
Process exited with code 255.