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
>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php