Re: Introducing "Array Of" RFC

From: Date: Wed, 15 Jan 2014 20:19:45 +0000
Subject: Re: Introducing "Array Of" RFC
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-71153@lists.php.net to get a copy of this message
On Wed, Jan 15, 2014 at 3:09 PM, Philip Sturgeon <pjsturgeon@gmail.com>wrote: > > Ok, ignoring the int stuff as PHP doesn't generally do that. We don't > want to broach that topic here. > > As for allowing null, this feature is currently intended as a > syntactic representation of: > > foreach ($foos as $foo) { > if (! $foo instanceof Face) { > throw new Exception ('AAAGGGGGHHH!'); > } > } > > You are suggesting: > > foreach ($foos as $foo) { > if (! is_null($foo) and ! $foo instanceof Face) { > throw new Exception ('AAAGGGGGHHH!'); > } > } > > How do people feel about that? > > PHP disallows passing NULL in a function like: function foo(MyClass $obj) {} Unless you explicitly allow it to be null: function foo(MyClass $obj = null) { } The first instance will throw an error: PHP Catchable fatal error: Argument 1 passed to foo() must be an instance of MyClass, null given I think this implementation (MyClass[]) should be consistent this when passing null.

« previous php.internals (#71153) next »