php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73487 Non-static method does not throw E_DEPRECATED
Submitted: 2016-11-10 12:44 UTC Modified: 2016-11-10 15:00 UTC
From: vyants at dengisrazy dot ru Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.0.13 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vyants at dengisrazy dot ru
New email:
PHP Version: OS:

 

 [2016-11-10 12:44 UTC] vyants at dengisrazy dot ru
Description:
------------
PHP does not throw E_DEPRECATED exception when non static method calls as static inside object.

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

class Foo {
    public function bar()
    {
        echo "1";
    }
    public function bar2()
    {
        static::bar();
    }
}

$class = new Foo();

//throw E_DEPRECATED
$class::bar();
//!!! no exception
$class->bar2();

Expected result:
----------------
I expect 2 E_DEPRECATED

Actual result:
--------------
$class::bar() - throw Exception
but $class->bar2() - work without exception

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-10 15:00 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-11-10 15: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

"static::bar()" does not mean to call the bar method statically. Rather the "static" indicates the use of late static binding (LSB) and means to call the bar method of the class which was originally invoked. Just like how "self::" means to call a method on the class currently executing, or "parent::" on the superclass.

See example #3 in the documentation for late static binding.
http://php.net/language.oop5.late-static-bindings#language.oop5.late-static-bindings.usage
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 21:01:32 2024 UTC