Edit report at http://bugs.php.net/bug.php?id=51391&edit=1

 ID:               51391
 Updated by:       ahar...@php.net
 Reported by:      byoung at bigbluehat dot com
 Summary:          Static methods called as self::fun() always resolve to
                   class of its declaration
-Status:           Open
+Status:           Bogus
 Type:             Feature/Change Request
 Package:          Class/Object related
 Operating System: Mac OS X
 PHP Version:      5.3.2

 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You need to use Late Static Binding: see the manual at
http://php.net/lsb for more details.


Previous Comments:
------------------------------------------------------------------------
[2010-03-25 16:15:33] byoung at bigbluehat dot com

Description:
------------
Static methods called using self::fun() resolve the parent class's
method even called from the child class. Sample code provided here (and
below):

http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php#49541

Test script:
---------------
<?php



class ExampleSuperclass

{

    static function classType()

    {

        return "superclass";

    }



    static function doSomething()

    {

        echo "doing something with " . self::classType();

    }

}



class ExampleClass extends ExampleSuperclass

{

    static function classType()

    {

        return "subclass";

    }

}



ExampleClass::doSomething();

// output is "doing something with superclass"!



?>

Expected result:
----------------
Expected behavior is to output "doing something with subclass."

Actual result:
--------------
Output is currently (in PHP 5.3.2) "doing something with superclass"!


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51391&edit=1

Reply via email to