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
 [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 16:01:29 2024 UTC