PHP

Static Class Variables

<?php
   class employee {
      static public $NextID = 1;
      public $ID;

      public function __construct() {
         $this->ID = self::$NextID++;
      }
   }

   $bob = new employee;
   $jan = new employee;
   $simon = new employee;

   print $bob->ID . "\n";
   print $jan->ID . "\n";
   print $simon->ID . "\n";
   print employee::$NextID . "\n";
?>

José M. Vidal .

28 of 33