I am learning PHP these days. Sorry, if my below query look dumb.
<?php
class A
{
var $parent;
var $app;
function A($parent) {
$this->parent = $parent;
if ($parent->isApplication()) {
$this->app = $parent;
} else {
$this->app = $parent->getApplication();
}
}
}
?>
<?php
class B extends A
{
private $app;
private $cfg;
public B() {
$this->app = parent::$app;
$this->cfg = $this->app->cfg;
}
}
?>
<?php
class C extends A {
function x(){
new B($this); // calling somewhere in some
}
}
?>
How do I use $this
inside subclass 'B', I knew that I can use $this inside some function, BUT my intention is to use $app everywhere in that php file, so I am trying to create $app just inside class so that I can use this $app variable anywhere, otherwise I would have used $this inside some function.
Here is my query:
How can I able to use $this->app
just inside class?
UPDATE:
<?php
class A
{
var $parent;
var $app;
function Canvas($parent) {
$this->parent = $parent;
if ($parent->isApplication()) {
$this->app = $parent;
} else {
$this->app = $parent->getApplication();
}
}
}
?>
<?php
class B extends A
{
private $app;
private $cfg;
public Canvas_Access_Approval() {
$this->app = parent::$app;
$this->cfg = $this->app->cfg;
}
}
?>
<?php
class C extends A {
function x(){
new B($this);
}
}
?>
Getting Error as: PHP Parse error: syntax error, unexpected 'B' (T_STRING), expecting variable (T_VARIABLE)