# Overloading

- Thread: https://externals.io/message/38389
- Original archive: https://news-web.php.net/php.internals/38389
- Started by Tinsley on 2008-06-19T12:58:37+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #38389 — Tinsley — 2008-06-19T12:58:37+00:00

URL: https://externals.io/message/38389#38389

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

---

## #38416 — Saulo Vallory — 2008-06-19T16:12:08+00:00

URL: https://externals.io/message/38389#38416 · In reply to: #38389

I'm developing a PHP framework and had the same issue sometimes... I think
it was already discussed in the list, did you searched the archives?

Saulo

On Thu, Jun 19, 2008 at 9:58 AM, Tinsley, Mark <MTinsley@dallasairmotive.com>
wrote:

> 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
