php class private property access outside class -
class { private $x=100; private $y=200; } $a=new a(); $x=(array) $a; foreach($x $key=>$val) { echo $x[$key]; }
i have issue private
variable of class a
.
class private variable access outside class when typecasting object array. should not access outside class. above example can access private variable of class a.
here result
100200
how can resolve issue?
you're not accessing private members there. you've got array holding state of object. encapsulation preserved, you're not allowed private member manipulation outside class blocks.
now you're allowed bend on backwards , object state can use whatever, that's poorly written client.
there's language can do, should free write good/bad code in language.
Comments
Post a Comment