I saw this code:
public function query( $query )
{
$full_query = $this->link->query( $query );
if( $this->link->error )
{
$this->log_db_errors( $this->link->error, $query );
return false;
}
else
{
return true;
}
}
included in a class definition. Please explain what this kind of code means: a->b->c
. I know that a->b
is used When accessing a method or a property of an instantiated class. But can not understand how to interpret("read,understand,translate") a->b->c
It means that property b of object a is also an object. So you're getting property c of property b of object a.
class a {
public $b;
function __construct() {
$this->b = new b;
}
}
class b {
public $c;
function __construct() {
$this->c = 'Hello';
}
}
$a = new a;
echo $a->b->c; // outputs Hello.
Object a has a property, b, that is itself an object having c as a method or property. In terms of the code posted, $this, the object whose source you are viewing has a property -link - that is an object. Since link is also an object, it can (and does) have properties, two of which are query and error.