Re: Return Type Hinting for Methods RFC

From: Date: Thu, 22 Dec 2011 15:43:23 +0000
Subject: Re: Return Type Hinting for Methods RFC
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-57006@lists.php.net to get a copy of this message
On Dec 22, 2011, at 10:18 AM, Oleg Oshmyan wrote: >> public function \Customer getCustomer(){ >> return $this->customer; >> } >> >> If the $customer instance variable is not declared with the type Customer >> then first of all IDE will not be able to spot an error, second compiler may >> have a slighly harder time of detecting a mismatch. > > The compiler does not even try to detect a mismatch; type hinting is > taken into account at run-time only. So whenever this function executes, > if it tries to return a value that is not a \Customer, a run-time error > will be reported. The only exception is implementing an interface that defines a returned type hint. This is detected at compile time but only to the point that the implemented method prototype is the same type hint. If it is not, an E_COMPILE_ERROR is raised. The runtime error raised is an E_RECOVERABLE_ERROR. > > -- > Oleg > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.internals (#57006) next »