FAQ
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

Search Discussions

  • Saulo Vallory at Jun 19, 2008 at 4:12 pm
    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 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



    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Tinsley, Mark at Jun 20, 2008 at 12:52 pm
    I only could find two from 2005.
    http://news.php.net/php.internals/17491
    http://news.php.net/php.internals/14558

    It doesn't look like much discussion. I'm new to that web interface; not
    sure if it will show the thread.

    Why don't we discuss adding this to the PHP6 release? I see it as a very
    helpful addition and can't see a reason why we could not add it.

    Mark


    -----Original Message-----
    From: Saulo Vallory
    Sent: Thursday, June 19, 2008 11:12 AM
    To: internals Mailing List
    Subject: Re: [PHP-DEV] Overloading

    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
    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



    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Marcus Boerger at Jun 20, 2008 at 2:28 pm
    Hello Mark,

    we discussed overloading a hell lot of times an dthe conclusionj always
    and every single time has been NO. It would mean a large slowdown for
    every single PHP application out there and it is not really that much
    halpful. In fact it makes code less readable and maintainable so it
    opposes the KISS (Keep It Simple Safe) approach of PHP.

    marcus

    Friday, June 20, 2008, 2:51:44 PM, you wrote:
    I only could find two from 2005.
    http://news.php.net/php.internals/17491
    http://news.php.net/php.internals/14558
    It doesn't look like much discussion. I'm new to that web interface; not
    sure if it will show the thread.
    Why don't we discuss adding this to the PHP6 release? I see it as a very
    helpful addition and can't see a reason why we could not add it.
    Mark
    -----Original Message-----
    From: Saulo Vallory
    Sent: Thursday, June 19, 2008 11:12 AM
    To: internals Mailing List
    Subject: Re: [PHP-DEV] Overloading
    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
    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



    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php




    Best regards,
    Marcus
  • Lukas Kahwe Smith at Jun 25, 2008 at 2:51 pm

    On 20.06.2008, at 16:28, Marcus Boerger wrote:

    Hello Mark,

    we discussed overloading a hell lot of times an dthe conclusionj
    always
    and every single time has been NO. It would mean a large slowdown for
    every single PHP application out there and it is not really that much
    halpful. In fact it makes code less readable and maintainable so it
    opposes the KISS (Keep It Simple Safe) approach of PHP.
    FYI, for future reference I at least added a link to the rfc page to
    this thread:
    http://wiki.php.net/rfc#declined

    regards,
    Lukas Kahwe Smith
    mls@pooteeweet.org
  • Tinsley, Mark at Jun 25, 2008 at 3:06 pm
    Thank you Lukas.

    Mark Tinsley
    Developer
    Dallas Airmotive
    (214) 353-6739
    mtinsley@dallasairmotive.com

    -----Original Message-----
    From: Lukas Kahwe Smith
    Sent: Wednesday, June 25, 2008 9:51 AM
    To: Marcus Boerger
    Cc: Tinsley, Mark; internals@lists.php.net
    Subject: Re: [PHP-DEV] Overloading

    On 20.06.2008, at 16:28, Marcus Boerger wrote:

    Hello Mark,

    we discussed overloading a hell lot of times an dthe conclusionj
    always
    and every single time has been NO. It would mean a large slowdown for
    every single PHP application out there and it is not really that much
    halpful. In fact it makes code less readable and maintainable so it
    opposes the KISS (Keep It Simple Safe) approach of PHP.
    FYI, for future reference I at least added a link to the rfc page to
    this thread:
    http://wiki.php.net/rfc#declined

    regards,
    Lukas Kahwe Smith
    mls@pooteeweet.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedJun 19, '08 at 12:59p
activeJun 25, '08 at 3:06p
posts6
users4
websitephp.net

People

Translate

site design / logo © 2022 Grokbase