PHP make class propery inheritable

walsulami

New Member
i have 2 classes A and B that extends A. A has a public property and i want that on the instances of B that property can't be accessible. I try to explain better:\[code\]class A{ public $prop;}class B extends A{ ...}$instance=new B;$instance->prop; //This must throw an error like "Undefined property prop"\[/code\]I tried with the \[code\]final\[/code\] keyword but it's only available for methods not for properties. I tried also by setting the same property as \[code\]private\[/code\] on B but PHP does not allow to change the access level from public to private or protected.Maybe there's a simple solution to this problem but i can't find it so do you know a way to do this?
 
Back
Top