note 74355 added to language.oop5.overloading
| From: | jamesatthunder-removeme-monkeydotnet at osu1 dot php dot net | Date: | Sat, 07 Apr 2007 09:14:25 +0000 |
| Subject: | note 74355 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125161@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 87.124.64.96
Probable Submitter: 82.39.155.185
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/74355
Del: integrated -- https://master.php.net/note/delete/74355/integrated
Del: useless -- https://master.php.net/note/delete/74355/useless
Del: bad code -- https://master.php.net/note/delete/74355/bad+code
Del: spam -- https://master.php.net/note/delete/74355/spam
Del: non-english -- https://master.php.net/note/delete/74355/non-english
Del: in docs -- https://master.php.net/note/delete/74355/in+docs
Del: other reasons-- https://master.php.net/note/delete/74355
Reject -- https://master.php.net/note/reject/74355
Search -- https://master.php.net/manage/user-notes.php