On Wed, Jan 15, 2014 at 3:09 PM, Philip Sturgeon <[email protected]>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.