note 87137 added to function.aggregate
| From: | mail at bealers dot com | Date: | Thu, 20 Nov 2008 18:14:35 +0000 |
| Subject: | note 87137 added to function.aggregate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146777@lists.php.net to get a copy of this message | ||
I had to fix someone else's php4 code to work under php5 that was b0rked due to aggregate not
working, here's how I did it.
<?php
class shell { }
$classes = array("foo", "bar", "baz");
function php5aggregate($holdingClass, $className)
{
// use php5 reflection to suss out the method names for the given class
// http://uk.php.net/manual/en/language.oop5.reflection.php
$reflect = new ReflectionClass($className);
foreach ($reflect->getMethods() as $method)
{
// copy the method to $holdingClass
// http://www.php.net/manual/en/function.runkit-method-copy.php
runkit_method_copy($holdingClass, $method->getName(), $className);
}
}
if (version_compare(PHP_VERSION, '5.0.0') === 1)
{
/**
* aggregate() does not exist in php5, so use our custom function
* note, our custom aggregate function takes the holding class *name*
* which is instantiated afterwards, this is different to how the php4 function works
*/
foreach($classes as $value)
{
php5aggregate("shell",$value);
}
$shell = new shell;
}
else
{
// php4
$shell = new shell;
foreach($classes as $value)
{
aggregate($shell,$value);
}
}
?>
----
Server IP: 92.48.74.199
Probable Submitter: 81.138.23.229
----
Manual Page -- http://www.php.net/manual/en/function.aggregate.php
Edit -- https://master.php.net/note/edit/87137
Del: integrated -- https://master.php.net/note/delete/87137/integrated
Del: useless -- https://master.php.net/note/delete/87137/useless
Del: bad code -- https://master.php.net/note/delete/87137/bad+code
Del: spam -- https://master.php.net/note/delete/87137/spam
Del: non-english -- https://master.php.net/note/delete/87137/non-english
Del: in docs -- https://master.php.net/note/delete/87137/in+docs
Del: other reasons-- https://master.php.net/note/delete/87137
Reject -- https://master.php.net/note/reject/87137
Search -- https://master.php.net/manage/user-notes.php