php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #74338 separate namespace of static member and non-static member
Submitted: 2017-03-30 07:35 UTC Modified: 2017-03-30 08:20 UTC
From: uukoo at 163 dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 7.1.3 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-03-30 07:35 UTC] uukoo at 163 dot com
Description:
------------
Can we separate namespace of static member and non-static member. So we can declare static and non-static member with same name. 

Test script:
---------------
class Foo
{
    public function bar()
    {
        echo 'This is a non-static method.';
    }

    static public function bar()
    {
        echo 'This is a static method.';
    }
}

// What we want

Foo::bar();       // echoes 'This is a static method.'
(new Foo)->bar(); // echoes 'This is a non-static method.'

// Actually happens
Fatal error:  Cannot redeclare Foo::bar() been thrown.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-30 08:20 UTC] requinix@php.net
-Status: Open +Status: Wont fix
 [2017-03-30 08:20 UTC] requinix@php.net
Contrary to popular belief, :: does not mean a static call. It is called the scope resolution operator because that is what it does: resolve scope. You've probably used it before with a parent::__construct in a constructor, and that's definitely not a static call.

Foo::bar always refers to the same method. When used inside of the Foo scope (which includes child classes) bar may be either an instance or static method, and PHP will call it appropriately. When used outside of Foo the method must be static because there is no instance available for PHP to use.
parent, self, and static work similarly but target different scopes: respectively, the parent class (or a further ancestor), the current class, and the LSB class.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Dec 05 06:01:23 2020 UTC