static class properties : static properties « Class « PHP






static class properties


<?php

   class visitors
   {
      private static $visitors = 0;

      function __construct()
      {
         self::$visitors++;
      }

      static function getVisitors()
      {
         return self::$visitors;
      }

   }

   $visits = new visitors();
   echo visitors::getVisitors()."<br />";

   $visits2 = new visitors();
   echo visitors::getVisitors()."<br />";

?>

           
       








Related examples in the same category

1.static class members
2.Using the -> and :: operators to call hypnotize
3.Using Static Methods and Properties to Limit Instances of a Class (PHP 5 Only)
4.Use the static modifier to change a member or method