The static variable life cycle differs in PHP and Java

Source: Internet
Author: User
<%!  Static class Count {      private static int count = 0;      public static int GetCount () {          count++;          return count;      }  }  %>  <%   out.print (Count.getcount ());  %>  

Continuous access through the browser, will be output separately: 1,2,3,4,5,6,........

<?php  class count{      private static $count = 0;      public static function GetCount () {self          :: $count + +;          Return self:: $count;      }  }  Echo Count::getcount ();  ? >  

Continuous access through the browser, will be output separately: 1,1,1,1,1,1,........

Summarize

1. The static variable of Java dies with the exit of the Java Virtual machine, and the static variable persists during the Java Virtual machine operation.

2, PHP static variable only for one request (a PHP file execution), PHP file execution, the static variable is also randomly extinct, again request (Execute the PHP file again), the static variable is recreated.

The static variable life cycle differs in PHP and Java

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.