Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 1.95 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. php acces to properties of a containing object
  2. var aaa = new function () {
  3.     that = this;
  4.     that.bbb  = 'foo';
  5.     this.ccc = new function () {
  6.         this.ddd = 'bar';
  7.         this.eee = function () {
  8.             return that.bbb+this.ddd;
  9.         }
  10.     }
  11. }
  12.        
  13. class bbb {
  14.     public $ccc = 'bar';
  15.         function __construct () {
  16.             echo($that->aaa.$this->ccc);
  17.         }
  18. }
  19. class aaa {
  20.     public $that;
  21.     public $aaa = 'foo';
  22.     public $bbb;
  23.     function __construct () {
  24.         echo($this->aaa);
  25.         $this->$bbb = new bbb();
  26.         $this->$that = $this;
  27.     }
  28. }
  29. $a = new aaa ();
  30.        
  31. $this->bbb = new bbb ($this);
  32.  
  33. class bbb {
  34.     public $that;
  35.     function __contruct ($parent) {
  36.         $that = $parent
  37.         ....
  38.     }
  39. }
  40.        
  41. $aaa = (object)array(
  42.     'bbb' => 'foo',
  43.     'ccc' => (object) array(
  44.         'ddd' => 'bar',
  45.         'eee' => function() use(&$aaa){ $self = $aaa->ccc; return $aaa->bbb.$self->ddd; }
  46.     ),
  47. );
  48.  
  49. echo call_user_func($aaa->ccc->eee);
  50.        
  51. $aaa = (object)array(
  52.     'bbb' => 'foo',
  53.     'ccc' => (object) array(
  54.         'ddd' => 'bar',
  55.         'eee' => function() use(&$aaa) { return $aaa->bbb.$this->ddd; }
  56.     ),
  57. );
  58.  
  59. $aaa->ccc->eee = $aaa->ccc->eee->bindTo($aaa->ccc);
  60. echo call_user_func($aaa->ccc->eee);
  61.        
  62. $tmp = function() {
  63.     $that = new stdClass();
  64.     $that->bbb = "foo";
  65.  
  66.     $tmp = function() use ($that) {
  67.         $this_ = new stdClass();
  68.         $this_->ddd = "bar";
  69.         $this_->eee = function() use ($that, $this_) {
  70.             return $that->bbb . $this_->ddd;
  71.         };
  72.         return $this_;
  73.     };
  74.     $that->ccc = $tmp();
  75.     return $that;
  76. };
  77.  
  78. $aaa = $tmp();
  79.  
  80. var_dump( call_user_func( $aaa->ccc->eee ));
  81. //string(6) "foobar"
  82.        
  83. class bbb {
  84.     function __construct ($parrent) {
  85.         echo $parrent->ccc;
  86.     }
  87. }
  88.  
  89. class aaa {
  90.     public $aaa = 'foo';
  91.     public $bbb;
  92.     public $ccc = 'bar';
  93.  
  94.     function __construct () {
  95.         echo $this->aaa;
  96.         $this->bbb = new bbb($this);
  97.     }
  98. }
  99.  
  100. $a = new aaa();