fork download
  1. <?php
  2. class Foo {
  3. public $name;
  4. public $type;
  5.  
  6. public function __construct($name, $type) {
  7. $this->name = $name;
  8. $this->type = $type;
  9. }
  10. }
  11.  
  12. $s = new SplObjectStorage();
  13.  
  14. $first = new Foo('first', 0);
  15. $second = new Foo('second', 0);
  16. $third = new Foo('third', 1);
  17. $fourth = new Foo('fourth', 1);
  18.  
  19. $s->attach($first);
  20. $s->attach($second);
  21. $s->attach($third);
  22. $s->attach($fourth);
  23.  
  24. print_r($s);
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
SplObjectStorage Object
(
    [storage:SplObjectStorage:private] => Array
        (
            [0000000029a68279000000006f869372] => Array
                (
                    [obj] => Foo Object
                        (
                            [name] => first
                            [type] => 0
                        )

                    [inf] => 
                )

            [0000000029a68278000000006f869372] => Array
                (
                    [obj] => Foo Object
                        (
                            [name] => second
                            [type] => 0
                        )

                    [inf] => 
                )

            [0000000029a6827f000000006f869372] => Array
                (
                    [obj] => Foo Object
                        (
                            [name] => third
                            [type] => 1
                        )

                    [inf] => 
                )

            [0000000029a6827e000000006f869372] => Array
                (
                    [obj] => Foo Object
                        (
                            [name] => fourth
                            [type] => 1
                        )

                    [inf] => 
                )

        )

)