php - Accessing a class variable from within a nested class -


my class structure follows,

class core{       public $variable = "test";        class subclass{             // functions, etc        }        // functions etc } 

i need access variable $variable within subclass class, cannot think of way it. have tried $this->this->variable without success.

edit while incorrect syntax, how class system setup (and achieved using includes).

assuming had proper inheritance model set up, use parent::. code as-is flat-out syntax error. cannot nest classes that.

class core {    public $var = 'test'; }  class subclass extends core {    function foo() {       $localvar = parent::$var;    } } 

comment followup:

perhaps more this?

class core {     public $variable = 'foo';     function __construct() {        $this->subclass = new subclass($this->variable);     } }  class subclass {     public $corevariable;     function __construct(&$var) {        $this->corevariable = $var;     } } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -