Overloading
| From: | Tinsley, Mark | Date: | Thu, 19 Jun 2008 12:58:37 +0000 |
| Subject: | Overloading | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-38389@lists.php.net to get a copy of this message | ||
What about the addition of overloading for PHP 6?
I am not totally up to date on the developments of the parameter type
hints. I briefly read the meeting minutes for PHP 6.
What about with the type hints we have now?
class moo
{
public static function foo(FooClass $FooVar)
{
// do something
}
public static function foo(BooClass $BooVar)
{
// do something
}
}
I have a project where we had to do a sort of pseudo overloading
Class moo
{
/**
* Accept the superclass or any of its sub classes
*/
public static function foo(FooSuperClass $Foo)
{
switch (true)
{
case $Foo instanceof FooClass:
$method = 'fooFoo';
break;
case $Foo instanceof BooClass:
$method = 'fooBoo';
break;
default:
throw new Exception('Unrecognized type: ' .
get_class($Foo));
break;
}
call_user_func(array(self, $method), $Foo);
}
private static function fooFoo(FooClass $FooVar)
{
// do something
}
private static function fooBoo(BooClass $BooVar)
{
// do something
}
}
Mark