On 13 Jul 2014, at 17:29, Rowan Collins <[email protected]> wrote:
> It's an interesting thought, but we currently have the object keyword for
> that particular use case. In some languages, having a base object is useful
> because functionality can be defined there, but PHP provides no way of
> altering existing classes, limiting that use too.
There’s no such type hint though:
$ php -r 'function foo(object $x) {} foo(new StdClass);’
PHP Catchable fatal error: Argument 1 passed to foo() must be an instance of
object, instance of stdClass given, called in Command line code on line 1 and
defined in Command line code on line 1
Perhaps one should be added? Not in this RFC though, obviously.
> Personally, I'm too much of a fan of PHP's arrays to bother with stdClass at
> all; if you want to future-proof things, it's not that hard to write
> placeholders ready for later implementation.
I’m thinking more about dealing with JSON and such which give you an object.
Perhaps you might have a FooBar->fromObject() method that can be passed another
FooBar to clone it, or an object decoded from JSON. Though in that particular
case there’s no real need for a type hint.
--
Andrea Faulds
http://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php