Re: Simplest way of enforcing an array of instances of a specific class but treating the whole thing as an array.
| From: | Richard Quadling | Date: | Thu, 24 Feb 2011 17:20:24 +0000 |
| Subject: | Re: Simplest way of enforcing an array of instances of a specific class but treating the whole thing as an array. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311566@lists.php.net to get a copy of this message | ||
On 24 February 2011 12:43, Richard Quadling <rquadling@gmail.com> wrote:
> Hi.
>
> Brain being a little slow today.
>
> My objective is to enforce a parameter to a method to be an array of a
> specific class (or null).
>
> The specific class is LatLng.
>
> I want to be able to pass an array of LatLngs to a method.
>
> I know I can hint this as ...
>
> function(array $LatLngs) {...}
>
> and then in the array processing loop, use ...
>
> if ($element instanceof LatLng) {...}
>
> But I have a LOT of different types that can exist in arrays and I
> want to enforce the commonality of the type.
>
>
> I think I need a class of LatLngs and this has to implement an
> Traversable and ArrayAccess interfaces.
>
> But I'm not sure.
>
> Anyone got any clues / reading?
>
> Thanks.
>
> Richard.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>
And it seems that ArrayObject is my start point.
Richard.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY