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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 07:01:26 2025 UTC