Simplest way of enforcing an array of instances of a specific class but treating the whole thing as an array.

From: Date: Thu, 24 Feb 2011 12:43:00 +0000
Subject: Simplest way of enforcing an array of instances of a specific class but treating the whole thing as an array.
Groups: php.general 
Request: Send a blank email to php-general+get-311559@lists.php.net to get a copy of this message
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

« previous php.general (#311559) next »