In OOP, sometimes you see something like this:
$memberID = $system->members->memberID();
I was interested and completely confused in the part where it is. ->members->...How does it work?
For example, let's say I have a class that I call the called $systems, then how can I put ->members->after it to start the member class?
I only know how to do something like that:
$system = new system();
$memberID = $system->memberID();
But I would like to know how to do this:
$system = new system();
$memberID = $system->members->memberID();
Thank!
- UPDATE - Here's a small update, thanks to everyone who helped me this far! You guys really pointed me in the right direction, I really have a great answer to my own question! :) And thanks to the moderator who edited this question, sorry, I was not familiar with the bbcode syntax.
, - , , → members- > __get(), - "new members()". , , .
, , :
<? class system {
public function __get($name){
$file = 'lib/'.$name;
if(file_exists($file)){
require_once($file);
$classname = $name;
$this->$name = new $classname($this);
return $this->$name;
}else{
die('Class '.$name.' could not be loaded (tried to load class-file '.$file.')');
}
}
}? >
, - , :
$system = new system();
$system->members->functionHere();
lib.
, . , Google, , , !