[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    [PHP] Simplest way of enforcing an array of instances of a specific class
From:       Richard Quadling <rquadling () gmail ! com>
Date:       2011-02-24 12:43:00
Message-ID: AANLkTi=md1sf4=PjiKLg34VydEgQXuiF8j+sv6sxnQ1t () mail ! gmail ! com
[Download RAW message or body]

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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic