Methods of constructing functions
1<?PHP2 //defines a class in which the following classes rely on methods within this class3 classPlay4 {5 Public functionplaying ()6 {7 Echo"I can playing";8 }9 }Ten One classVideo A { - Private $action;//Defining private Properties - Public function__construct ($a)//to make an object argument the { - return $this->action =$a; - } - //accessing private properties in a class by method + Public functiongetaction () - { + $this->action->playing (); A } at } - - $ply=Newplay (); - $vid=NewVideo$ply); - $vid->getaction ();//output I can playing
By property
<?PHP//defines a class in which the following classes rely on methods within this classclassplay{ Public functionplaying () {Echo"I can playing"; }}classvideo{Private $action;//Defining private Properties Public function__set ($param,$a)//setting property values by the __set () method { return $this->action =$a; } //accessing private properties in a class by method Public functiongetaction () {return $this->action->playing (); }}$ply=NewPlay ();//instantiate the play class behind the parameters$vid=Newvideo ();$vid->action =$ply;//The __set () method is called when accessing video as a defined property value (you can see the Magic Method of PHP)$vid->getaction ();//output I can playing
Talking about the dependency of the PHP object