php class knowledge --- constant drip

  • Constants in the class of internal and external can be accessed through the class name :: constant names
  • Constant no access modifier
  • The difference is variable, not a constant value in double quotes, and the variable can
<? PHP 
class mycoach
{
public $ name = "Chen Peichang";
CONST = 22 is hisage;
public $ Age = 22 is;
Private Favorite $ = "favorite cauldron D";
public the __construct function ()
{
echo $ this-> name. " Christina ".mycoach :: hisage $ this-> favorite.PHP_EOL;.
echo" constants can not be enclosed in double quotes values: ------- Chen Peichang brother :: hisage Christina mycoach ".PHP_EOL;
echo" variable value may be in double quotes: ------- Chen Peichang brother Christina this- $> Age ".PHP_EOL;
}
public function the __get (Key $)
{
return the this $ -> $ Key;
}
public function the __set ( Key $, $ value)
{
$ the this -> Key $ = $ value;
}
}
$ mycoach new new CPC = ();
?>

Output:

Christina Chen Peichang like 22 Ding cauldron
constant values can not be enclosed in double quotes: ------- brother Chen Peichang Christina mycoach :: hisage
variables can be enclosed in double quotes values: ------- Chen Peichang Christina brother 22

Guess you like

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