> -----Original Message-----
> From: Philip Sturgeon [mailto:[email protected]]
> Sent: Wednesday, January 15, 2014 10:25 PM
> To: Robert Stoll
> Cc: Marco Pivetta; Kristopher; [email protected]
> Subject: Re: [PHP-DEV] Introducing "Array Of" RFC
>
> On Wed, Jan 15, 2014 at 3:54 PM, Robert Stoll <[email protected]> wrote:
> >
> >
> >> -----Original Message-----
> >> From: Marco Pivetta [mailto:[email protected]]
> >> Sent: Wednesday, January 15, 2014 9:25 PM
> >> To: Kristopher
> >> Cc: Philip Sturgeon; Robert Stoll; [email protected]
> >> Subject: Re: [PHP-DEV] Introducing "Array Of" RFC
> >>
> >> On 15 January 2014 21:19, Kristopher <[email protected]> wrote:
> >>
> >> > I think this implementation (MyClass[]) should be consistent this when
> >> > passing null.
> >> >
> >>
> >> Even without the argument of consistency, the new syntax would be pretty
> >> much useless if NULL
was allowed, since every method would have start
> >> with a call to array_filter
.
> >>
> >> Marco Pivetta
> >>
> >
> > You could also think in a different way. NULL is basically a valid entry in an array. If
> > you apply the restriction
as
> implemented in the pull request then one cannot use the new syntax for arrays which allow NULL,
> that seems odd to me
as
> well. Especially since class/interface-types are reference types and I regard NULL as something
> equal to a
null-pointer.
> > Furthermore, if one does not want to support NULL in an array currently, then one probably
> > already uses an own
> collection implementation which already triggers and error, throws an exception respectively,
> when one tries to add
NULL
> to the collection.
> >
> > It seems the pull request does not yet support multidimensional arrays (e.g. Foo[][]) but
> > if we would stick to the
> restriction now then the consequence should be that this restriction also applies to
> multi-dimensional arrays. In my
opinion,
> we would spoil valid use cases this way for RFC and for future ones (in the case
> multi-dimensional arrays will be
introduced,
> other concepts could be affected as well).
> >
> > Thus I would suggest to remove this check and provide a further SPL data structure
> > implementation instead which does
> not allow null as entry if this feature is really needed. Seems more appropriate to me than
> making a restriction in
the
> language itself.
> >
> >
> >
>
> I would assume that the majority of people will be using this syntax
> to ensure the types of objects.
>
> In English:
>
> "I would like everything in this array to be Foo."
>
> That is much more programatically useful in my opinion than:
>
> "I would like everything in this array to be Foo or maybe null."
>
> If we go with the latter then I still have no idea what is in this
> variable, and have to do a whole bunch of checking or
> array_filter()ing, otherwise I am doing this:
>
> $possibleNullValue->getInfo(); // BOOM!
>
> Even if there are use-cases for allowing them I would suggest that
> there are probably more use-cases for denying them.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
Fair enough, the example with the English sentence makes pretty much sense from an average
user's point of view and thus
most PHP users would probably agree with you (don't take it wrong, I don't imply you are
average or something similar).
However, this should not be a decision based on whether many people are preferring it this way or
the other way round in
my opinion, since the restriction is going to make it impossible to use it for the use cases where
NULL is a valid
entry.
So, we should ask ourselves, do we really want to exclude a whole bunch of valid use cases or should
we decline the
restriction and put more effort in providing alternatives for non-null -containing collections.
See, if we do not introduce the restriction and provide a non-null-containing collection then all
use cases can be
supported. That is the way to go IMO.
Or do you have another idea how one can specify that the array can contain null?
And please consider, if you should suggest "function foo(Foo[] $foo=null)" implies that
$foo can also contain NULL then
we have another vague concept in PHP which has a double meaning -> $foo can be NULL and entries
in $foo can be NULL. But
maybe one does not want to allow NULL for $foo but only for members of $foo.