Re: [RFC][DISCUSSION] Object type hint
| From: | Stephen Reay | Date: | Mon, 24 Oct 2016 05:38:34 +0000 |
| Subject: | Re: [RFC][DISCUSSION] Object type hint | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96576@lists.php.net to get a copy of this message | ||
No, I don’t expect all objects to have the same properties.
So, today I learned that
$foo = 1; isset($foo->bar); doesn’t throw an error about
a non-object. However, property_exists *does* throw errors in that situation, as does
get_object_vars() - two situations where you *can* pass any object, so long as it is an object.
Like I said, the functionality is possible without it. But what functionality was impossible without
int/float/string type hints? They just make it much clearer, with less repeated boiler plate, what
arguments you can actually accept.
Cheers
Stephen
> On 24 Oct 2016, at 12:05, Stanislav Malyshev <smalyshev@gmail.com> wrote:
>
> Hi!
>
>> In the same way that Iterable type hint allows you to safely do a
>> foreach on an argument, object allows you to safely use property
>> accessor syntax (i.e. ->). For me it would be most useful in lower
>> level utility classes.
>
> Not sure I get this point. How you can safely use -> if you have no idea
> what object you've got? You certainly don't expect every object to have
> the same properties?
>
> --
> Stas Malyshev
> smalyshev@gmail.com
>