php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42936 calling a static variables using ->
Submitted: 2007-10-11 22:34 UTC Modified: 2007-10-11 23:25 UTC
From: bacrhr at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.4 OS: Windows XP
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bacrhr at gmail dot com
New email:
PHP Version: OS:

 

 [2007-10-11 22:34 UTC] bacrhr at gmail dot com
Description:
------------
I could call and change static variable from object or from class

Reproduce code:
---------------
class A{
    public static $pp;
    public function ch(){
	$this->pp+=2;
	print $this->pp.'<br>';
    }
}
$b = new A();
$b->ch();
print $b->pp;


Expected result:
----------------
I expected error

Actual result:
--------------
output is:
2
2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-11 23:25 UTC] johannes@php.net
The -> is for object access, but a static element belongs to the class. use self::$pp instead. Using -> for static acces would just lead to confusion.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 13:01:28 2024 UTC