Re: Behavior of classes type hinting together with the error handler
| From: | Nikita Popov | Date: | Fri, 13 Mar 2015 12:08:44 +0000 |
| Subject: | Re: Behavior of classes type hinting together with the error handler | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84678@lists.php.net to get a copy of this message | ||
On Fri, Mar 13, 2015 at 12:48 PM, Андрей Клюев <kluev.andrew@gmail.com>
wrote:
> Hello internals! My name is Andrew and I write php literally since
> childhood (something around 10 years),
> now PHP - is my profession.
> And today once again debugging foreign code, I was ready to go to the
> hospital to see a psychiatrist.
> First, some of the code:
> Do you think that can output this feature?
>
> function test(A $a)
> {
> var_dump(get_class($a));
> }
>
> I always thought that only 'string (1) "A"', I have never been so wrong
> (c).
>
> The code below will display 'string (1) "B"'
>
> class A {
> }
>
> class B {
> public $id = 1;
> }
>
> set_error_handler(function () {
> return true;
> });
>
> function test(A $a)
> {
> var_dump(get_class($a));
> }
>
> test(new B());
>
> I think this is very unexpected behavior, and suggest you to consider the
> possibility of removing this behavior in PHP7.
>
It has already been dropped by
https://wiki.php.net/rfc/engine_exceptions_for_php7
:)
As a side node, an "A $a" typehint does not make sure that get_class($a)
=== 'A', only that $a instanceof A.
Nikita