php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51391 Static methods called as self::fun() always resolve to class of its declaration
Submitted: 2010-03-25 16:15 UTC Modified: 2010-03-25 16:26 UTC
From: byoung at bigbluehat dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.2 OS: Mac OS X
Private report: No CVE-ID: None
 [2010-03-25 16:15 UTC] 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"!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-25 16:26 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-03-25 16:26 UTC] aharvey@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC