php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68568 Calling static method causing to call non static method with the same name
Submitted: 2014-12-08 14:48 UTC Modified: 2014-12-09 19:03 UTC
From: walid dot wah at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.6.3 OS: LINUX ARCHLINUX
Private report: No CVE-ID: None
 [2014-12-08 14:48 UTC] walid dot wah at gmail dot com
Description:
------------
calling a non existed static method is causing to call the shared parents' non static method

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

class Magic {
    public function delete() {
        echo "OMG CALLED!!".PHP_EOL;
    }
};


class EmptyClass extends Magic {

};



class MethodTest extends Magic {
    public function omg() {
        EmptyClass::delete();
    }
};


$obj = new MethodTest;

$obj->omg();
?>

Expected result:
----------------
PHP Fatal error:  Call to undefined method EmptyClass::delete()

Actual result:
--------------
it calls the non static inherited delete() method!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-08 19:00 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-12-08 19:00 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PHP allows you to call a non-static method statically but will warn about it with an E_DEPRECATED.
http://3v4l.org/lsngY
 [2014-12-09 13:15 UTC] walid dot wah at gmail dot com
the problem that i'm not calling the method statically for the current object i'm calling it from a different class which inherits the current class parent and that's why i reported it
 [2014-12-09 19:03 UTC] requinix@php.net
> the problem that i'm not calling the method statically for the current object
True.
> i'm calling it from a different class
True.
> which inherits the current class parent
Irrelevant.

delete() was inherited so the method is defined. It's a static call because the two classes are not directly related. Not a bug.
 [2014-12-09 19:03 UTC] requinix@php.net
-Type: Feature/Change Request +Type: Bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 19:01:30 2024 UTC