note 74355 deleted from language.oop5.overloading by bjori

From: Date: Sat, 07 Apr 2007 15:23:32 +0000
Subject: note 74355 deleted from language.oop5.overloading by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125171@lists.php.net to get a copy of this message
Note Submitter: james at thunder-removeme-monkey dot net Reason: ok idea but should be posted somewhere else ---- It is fustrating. As suggested in the PHP bugs list you could use ... <? if(is_array($view->list) || $view->list instanceof ArrayObject) { // ... } if(in_array($needle, (array)$view->haystack)) { // ... } ?> ... but these are pretty inadequate, especially when it comes to writing portable slot-in classes. Forcing "is_array()", "in_array()" and all the other array functions work natively with ArrayObject sounds ideal, but leads pretty quickly to untidy internals I'd guess (what if "TurnipObject" was also an array-type object) - unless EVERY array in the core was treated as an ArrayObject? Perhaps a potential solution to the core (assuming it uses something like the "instanceof" internally) would be adding the ability to override the "instanceof" operator in our classes, so we could have something like: <? /* Addition to ArrayObject class */ class ArrayObject { public function __instanceof($type) { /* Would need to check instanceof parent classes */ if($type=='array' || $type=='ArrayObject' || parent::__instanceof($type)) { return TRUE; } else { return FALSE; } } } /* Now, assuming is_array(x) calls something like "x instanceof array" internally */ $obj= new ArrayObject(); if(is_array($obj)) { /* would call __instanceof('array') */ print "It's an array all right"; } ?> Not ideal, not particularly tidy, but could lead to pretty flexible means of using custom classes to override core types like strings, bools, etc.

« previous php.notes (#125171) next »