$ This use of PHP classes and objects

concept:

$ This: read the properties of the class, the method can also be read;

No matter what name is generated object, $ this only refers to the current object.

<? PHP 


Class the User { 
  protected $ name; 

public function getName ($ name) { 

  return $ the this -> name = $ name;   // property acquired $ this class 

} 

public function sayName () { 

 return $ the this -> name; 

} 

public function funname () { 

  return $ the this -> sayName ();   // the method of obtaining the this class $ 

} 

} 

$ the Obj = new new the User;   // generating object 
$ obj-> getName ( "Lilei");
echo $ the Obj -> funname ();


>?

 

Guess you like

Origin www.cnblogs.com/web928943/p/12558548.html