|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: uukoo at 163 dot com
New email:
PHP Version: OS:


 [2017-03-30 07:35 UTC] uukoo at 163 dot com
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-30 08:20 UTC]
-Status: Open +Status: Wont fix
 [2017-03-30 08:20 UTC]
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-2021 The PHP Group
All rights reserved.
Last updated: Tue May 11 08:01:24 2021 UTC