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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 24 February 2011 18:28, David Harkness <david.h@xxxxxxxxxxxxxxxxx> wrote:
> If each array will contain a single type of object, but you need many of
> these arrays, each containing a different type of object, I recommend
> creating a generic "instances-of-class" array using ArrayObject. You can
> enforce the type in append(), offsetSet(), and exchangeArray() and then
> check the configured type in methods that want to enforce it.
> ÂÂ Âfunction drawMap(TypedArray $latLngs=null) {
> ÂÂ Â Â Âif ($latLngs && !$latLngs.containsOnly('LatLng')) {
> ÂÂ Â Â Â Â Âthrow new InvalidArgumentException('$latLngs must contain only
> LatLngs');
> ÂÂ Â Â Â}
> ÂÂ Â Â Â...
> ÂÂ Â}
> I guess since there are only three methods to override it wouldn't be too
> painful to create a separate class for each type to get method declaration
> type hinting. If you aren't containing too many classes and you pass them
> around a lot, it may be worth it since you won't have to test the container
> inside the method at all.
> ÂÂ Âfunction drawMap(LatLngArray $latLngs=null) ...
> Looks like someone beat us to it:
> ÂÂ Âhttp://liamgraham.wordpress.com/2007/05/21/typesafe-arrays-for-php/
> David
>

That's it and in the direction I was heading.

Thanks David - and liamgraham


-- 
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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux