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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 15 = ?
Subscribe to this entry?

 
 [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: Mon May 06 12:01:31 2024 UTC