fork download
  1. <?php
  2. class Foo {
  3. public $first;
  4. public $second;
  5.  
  6. public static $array = array();
  7.  
  8. public function __construct($first, $second) {
  9. $this->first = $first;
  10. $this->second = $second;
  11.  
  12. self::$array[] = $this;
  13. }
  14. }
  15.  
  16. $first = new Foo('first', 'first');
  17. $second = new Foo('second', 'second');
  18.  
  19. print_r(Foo::$array);
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Foo Object
        (
            [first] => first
            [second] => first
        )

    [1] => Foo Object
        (
            [first] => second
            [second] => second
        )

)