I am fairly new in PHP and want to ask a question. I know if you want to access a properties or method within a class or object you can use $this->properties
or $this->method
.
But I encountered a code like this $this->context->cart
Can someone please explain the meaning behind this code ?
If there is another similar question already being asked in SO can you please provide me the link, I will check it out.
Big Thanks
See and try it:
class class1 {
public $properties;
public $context;
function __construct(){
$this->properties = '$properties in class1';
$this->context = new class2(); // instance of class2
}
}
class class2 {
public $cart;
function __construct(){
$this->cart = '$cart in class2';
}
}
$obj = new class1();
echo $obj->properties;
echo $obj->context->cart;
context是另一个类的实例,用于该类的反向方法或属性
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.