fork(1) download
  1. <?php
  2.  
  3. class decorator {
  4. protected $decoratee;
  5. function __construct( $object ) {
  6. $this->decoratee = $object;
  7. }
  8. }
  9.  
  10. class test {
  11. function addObject( &$object ) {
  12. $object = $this->decorate( $object );
  13. }
  14. function addObjects( array &$objects ) {
  15. foreach( $objects as &$object ) {
  16. $this->addObject( $object );
  17. }
  18. }
  19. function decorate( $object ) {
  20. return new decorator( $object );
  21. }
  22. }
  23.  
  24. $dec = new test;
  25. $std = new StdClass;
  26. $a = array( $std );
  27. $dec->addObjects( $a);
  28. print_r( $std );
Success #stdin #stdout 0s 13112KB
stdin
Standard input is empty
stdout
stdClass Object
(
)