note 66153 deleted from language.oop5.typehinting by felipe
| From: | felipe@php.net | Date: | Sat, 15 Dec 2007 01:21:21 +0000 |
| Subject: | note 66153 deleted from language.oop5.typehinting by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133490@lists.php.net to get a copy of this message | ||
Note Submitter: mega-squall at caramail dot com
----
Type hinting cannot be used with array of instances of a given class. When submited to PHP Team,
idea got this answer :
" That's impossible and never will be. But you can do that more or less yourself. Derive a
class that implements ArrayAccess or reuse ArrayObject/ArrayIterator. And overload its offsetSet().
In the method body you add the check to ensure only what you want can go in. Now if that class
accepts only B's (B beeing an examble classname, ndla) you may call it ArrayOfB and the use
ArrayOfB as you typehint. "
This is obviously reaching the limit between "typing" and "type hinting" ...