php - $a->b = new cl(); How to call $a->x() from within $a->b->c() without having to pass $a as an argument to c(); -


php

class cla {      var $b;      function cla()     {         $this->b = new clb();     }      function x()     {       echo "testing";     } }           class clb {      function clb()     {      }      function c ($a)     {        $a->x();     } }  $a = new cla();  $a->b->c($a); 

how call c() without having pass $a;

calling method member of object 1 level current object method being called.

function c () {    ??->x(); } 

?? => object 1 level current object of method member

class cla {      public $b;      public function __construct() {         $this->b = new clb($this);     }      public function x() {       echo "testing";     } }           class clb {      private $a;      public function __construct($a) {         $this->a = $a;     }      public function c () {        $this->a->x();     } }  $a = new cla();  $a->b->c(); 

demo

note i've updated classes php5 php4


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -