php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44944 PHP Scope resolution operator
Submitted: 2008-05-08 10:12 UTC Modified: 2008-05-08 10:37 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: som dot guha at yahoo dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 5.2.6 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-05-08 10:12 UTC] som dot guha at yahoo dot com
Description:
------------
I am using php 5.2.5 version. I was testing the functionality of the scope resolution operator. In php.net site it stated that "The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden members or methods of a class.". Now if you check my following code:

class MyClass{
   public function showMyName(){
     echo "My Name";
   }
}

From the above code, I am able to access the showMyName() method without creating any object, with the help of scope resolution operator, like:
MyClass::showMyName();
If you check my code you can see that I have never declared the method as a static method. Show how I am able to access that method with the scope resolution operator. I think this is violating the OOPs rule.

 
 


Reproduce code:
---------------
class MyClass{
   public function showMyName(){
     echo "My Name";
   }
}

MyClass::showMyName();

Expected result:
----------------
Should generate an error.

Actual result:
--------------
My Name

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-08 10:37 UTC] derick@php.net
I agree with you, but it was decided not to make this a fatal error. If you have E_STRICT turned on (which I think you should), you will see this:

Strict standards: Non-static method MyClass::showMyName() should not be called statically in /home/derick/- on line 8

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 18:01:23 2020 UTC