1<?php
2 class User
3 {
4 private static $counter = 0;
5
6 public function __construct()
7 {
8 self::$counter++;
9 }
10 public function getCount()
11 {
12 return self::$counter;
13 }
14
15 public function __destruct()
16 {
17 self::$counter--;
18 }
19 }
20 $user1 = new User();
21 $user2 = new User();
22 $user3 = new User();
23 echo $user1->getCount().'<br>';
24 unset($user1);
25 echo $user2->getCount();
26
27?>
2 class User
3 {
4 private static $counter = 0;
5
6 public function __construct()
7 {
8 self::$counter++;
9 }
10 public function getCount()
11 {
12 return self::$counter;
13 }
14
15 public function __destruct()
16 {
17 self::$counter--;
18 }
19 }
20 $user1 = new User();
21 $user2 = new User();
22 $user3 = new User();
23 echo $user1->getCount().'<br>';
24 unset($user1);
25 echo $user2->getCount();
26
27?>