|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-02-27 20:49 UTC] paulscheltema at gmail dot com
Description:
------------
Hello dear developer(s),
When i setup a simple class with a protected/private var,
instanciate the class, and cast the instance to an array
i can access the protected/private var.
Reproduce code:
---------------
class test {
public $public = 'public';
private $private = 'private';
protected $protected = 'protected';
}
$t = new test;
$a = (array)$t;
print '<br>public: '.$a['public'];
print '<br>private: '.$a["\0test\0private"];
print '<br>protected: '.$a["\0*\0protected"];
Expected result:
----------------
Expected:
public: public
Or at most an Error like:
Cannot access private property test::$private
as the value of the private property
Actual result:
--------------
Result:
public: public
private: private
protected: protected
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
Maybe this explains it better: <?php class test { public $public = 'public'; private $private = 'private'; protected $protected = 'protected'; } $t = new test; var_dump($t); ?> And this will output everything, and it's expected and the correct behaviour. It's about the properties being isible/not-visible/writable to other classes. PPP is not meant for providing any security. (I admit, I'm bad at explaining things. :)