php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52968 Static private attributes visibility
Submitted: 2010-10-02 08:07 UTC Modified: 2010-10-03 06:05 UTC
From: czambran at csrg dot inf dot utfsm dot cl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: Irrelevant OS: Linux/Ubuntu Lucid Lynx
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:
24 + 33 = ?
Subscribe to this entry?

 
 [2010-10-02 08:07 UTC] czambran at csrg dot inf dot utfsm dot cl
Description:
------------
Static private attributes of a class can be directly by another non-friendly resource or file.



Test script:
---------------
If I define a class with static methods, as the following:

class Device{
    static private $id = 15;
}

For example, if the class Device is stored into device.class.php and I have another file called main.php and the implementation of main.php is the following:

<?php
include("device.class.php");
echo "The device's id is: ".Device::$id;
?>


Expected result:
----------------
The device's id is 15.

Actual result:
--------------
Not relevant results yet.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-02 08:16 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-10-02 08:16 UTC] rasmus@php.net
That's what private means.  You are not allowed to access it from outside of the 
class.  You can make a static accessor method in your Device class that returns 
it, if you like.
 [2010-10-02 10:48 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=303931
Log: - Substantially improved the documentation of strtr(). Closes bug #52968.
 [2010-10-03 06:02 UTC] czambran at csrg dot inf dot utfsm dot cl
[2010-10-02 06:16 UTC] rasmus@php.net

That's what private means.  You are not allowed to access it from outside of the 
class.  You can make a static accessor method in your Device class that returns 
it, if you like.

-----

Because that, the problem is that php is allowing to access it from outside, without the using of the static accessor method :P.

Greetings
 [2010-10-03 06:05 UTC] rasmus@php.net
No it doesn't, and your code shows it doesn't let it.  You said your expected 
result was for it to show 15, and it didn't.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 03:01:28 2024 UTC