Req #74338 [Opn->Wfx]: separate namespace of static member and non-static member

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=74338&edit=1

 ID:                 74338
 Updated by:         [email protected]
 Reported by:        uukoo at 163 dot com
 Summary:             separate namespace of static member and non-static
                     member
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            *General Issues
 PHP Version:        7.1.3
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2017-03-30 07:35:26] 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.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74338&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.