I am in this situation: I want that an object do a thing ONLY if it has been called by another object:
EX:
class obj{
private $doIt=false;
private function enableDoIt(){
$this->doIt=true;
}
public function fn(){
$obj= new obj();
$obj->enableDoIt(); // must work
}
}
$obj=new obj();
$obj->enableDoIt(); // <- must fail
I want to enable a setting only from my code and do not let the user of the class to set it, so I can't use public setters...
Any idea?
EDIT:
As I see in your comment, I need something like:
obj friend obj
This way I can use my private vars from inside my class with a new istance of myclass itself.
class obj{
private $count=0;
private function fn(){
nc=new obj();
nc->cont=2; //called from inside class obj -> want to work
}
}
nc=new obj();
nc->cont=2; //called from outside class obj -> want to not work