user845040
user845040

Reputation: 59

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->content['field_pr_link'];

is it a Drupal thing or PHP?

Upvotes: 4

Views: 215

Answers (3)

Ondrej Slinták
Ondrej Slinták

Reputation: 31910

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.

Upvotes: 1

Mark
Mark

Reputation: 1088

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.

Upvotes: 1

stevebot
stevebot

Reputation: 24005

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

Upvotes: 10

Related Questions