开发者

What is this: "->" in Drupal?

I am running into this -> in Drupal and cant find any docs on it.

I am using it like this print $node->cont开发者_高级运维ent['field_pr_link'];

is it a Drupal thing or PHP?


It's PHP. You are using it to access the content field on the node object.

See http://php.net/manual/en/language.oop5.php


That is the PHP "Operator Object". It is very poorly documented in the PHP manual. It allows you to reference the variables, constants, and methods of an object.

$a = $ObjectInstance->var; # get variable or constant
$ObjectInstance->var2 = "string"; # set variable
$ObjectInstance->method(); # invoke a method.


It's an operator used in scope of object to access its variables and methods.

Imagine having class as follows:

class Object {
    protected $variable;

    public function setVariable($variable) {
        $this->variable = $variable;
    }

    public function getVariable() {
        return $this->variable;
    }
}

You can see I'm accessing variables in scope of this class ($this) using -> operator. When I create instance, I'll be able to access also public methods / variables from the same scope, using the same operator:

$object = new Object();
$object->setVariable('Hello world');
echo $object->getVariable(); // 'Hello world'

In your case $node represents an object and content is public variable inside that object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜