Static usage in PHP

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.