1 <HTML> 2 <body> 3 <! -- Use in class --> 4 <? PHP 5 class teststatic {6 public static $ Country = 'China'; // you can use the public modifier 7 8 Public Function getcountry () {9 return self :: $ country; // use self10} 11 12 public static function getcountryst () {13 return self: $ country; To call the static variable in the class; 14} 15} 16 17 $ test = new teststatic (); 18 echo $ test-> getcountry (). '<br>'; 19 echo teststatic: getcountryst (). '<br>'; // you can call static method 2 directly in the form of class: staticfunc. 0 echo teststatic: $ country. '<br>'; // you can call static variable 21 directly using class: staticvar. 22 23 <! -- Use in script --> 24 <? Php25 static $ Country = 'Japan '; // the variables in the script cannot be modified with the public variable 26 echo $ country.' <br> '; 27?> 28 </body> 29
Page output
China
China
China
Japan