Re: Introducing "Array Of" RFC

From: Date: Fri, 28 Feb 2014 09:04:23 +0000
Subject: Re: Introducing "Array Of" RFC
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 28 February 2014 08:11, Crypto Compress
<[email protected]> wrote:
> Hello List,
>
>
>> So, should we allow nulls in an arrayof-style type hint?
>
>
> No. Null values (optional values) should be allowed within an
> nullable-arrayof-style type hint.
>
> Compare:    function foo(Bar $baz = null)
> and:    function foo(Bar $baz)
>
> This is not the same syntax and null is not a type.
>

Are you suggesting the following?

function foo(Bar[] $bars) // required to pass an array of Bar objects
function foo(Bar[] $bars = null) // required to pass an array of Bar
or null members

...because if so, how do I specify an optional array of Bar objects?
And how do I specify an optional array of Bar or null?

The whole concept of allowing null members seems to completely defeat
the purpose of the ArrayOf hint for me. I can understand wanting to
make the parameter optional, but I cannot see a use case for null
members from the point of view of the caller. I never null out members
of an array, I only omit them from the declaration or remove the
member from the array via e.g. unset() or stack operations (pop(),
shift() etc). YMMV of course, but for me allowing null members just
makes the callee's life more difficult and does not gain anything.


Thread (73 messages)

« previous php.internals (#72854) next »