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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -