Re: Introducing "Array Of" RFC

From: Date: Fri, 28 Feb 2014 09:57:19 +0000
Subject: Re: Introducing "Array Of" RFC
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-72858@lists.php.net to get a copy of this message
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
No. This is ambiguous, as you imply. I prefer c# syntax.
...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.
Have to agree, there is not too much value in this. ;) Usecase: No need to write a mock for third and seventh array element. In fact i can't think of other usecases. It's only a simple logical extension of "function (A $a = null)".

« previous php.internals (#72858) next »