php class self $ this knowledge can only be used in the current class

  • $ This is the current pointer to the object, self is a pointer to the current class
  • $ This method can only be used in members, it can not exist in a static method
  • self static methods and members of the methods can be used
  • self can access class constants, static properties, static methods, member method ---- that is, access to things like
  • There is also a self purpose: class-related properties in operation, when the method, if the class name :: properties and methods, then the class name changed, then go cry, so the safest way is to use self :: attribute, method
? < PHP
 class mycoach 
{ 
    public $ name = " Chen Peichang " ; 
    CONST hisage = 22 ;
     public  static $ earnfor = 2789 ;
     public  static $ address = " Chaoyang District, Sanlitun soho North Wu Tang " ;
     Private $ Favorite = " like Ding cauldron " ;
     public function __construct () 
    { 
        echo " {$ this-> name} So far, for the value of the equipment sold in the shop " . .mycoach :: $ earnfor " yuan ".PHP_EOL;
    }
    public static function workingaddr()
    {
        echo self::$address.PHP_EOL;
    }
}
$cpc = new mycoach();
$cpc->workingaddr();
?>

operation result:

Chen Peichang So far, the value of the equipment for the shop to sell 2789 yuan
, Chaoyang District, Sanlitun soho North Wu Tang

Guess you like

Origin www.cnblogs.com/saintdingspage/p/10988474.html