" is called the plug-in dereference operator. It is a method of calling a subroutine that passes parameters by reference. To reference the properties and methods of a class, use the "->" operator. The syntax is " Class -> member variables or member functions of the class"; the left side of the "->" operator is to obtain the instance of the class, and the right side will specify and call the methods and attributes of the left class."/> " is called the plug-in dereference operator. It is a method of calling a subroutine that passes parameters by reference. To reference the properties and methods of a class, use the "->" operator. The syntax is " Class -> member variables or member functions of the class"; the left side of the "->" operator is to obtain the instance of the class, and the right side will specify and call the methods and attributes of the left class.">

Home  >  Article  >  Backend Development  >  What does php arrow number mean?

What does php arrow number mean?

青灯夜游
青灯夜游Original
2023-01-10 10:38:511563browse

In PHP, the arrow sign "->" is called the inserted dereference operator. It is a method of calling a subroutine that passes parameters by reference. To reference the properties and methods of a class, use "- >" operator, the syntax is "class -> member variables or member functions of the class"; the left side of the "->" operator is to obtain the instance of the class, and the right side will specify the methods and attributes of the left class and call them .

What does php arrow number mean?

The operating environment of this tutorial: windows7 system, PHP8 version, DELL G3 computer

In php, the arrow number "-&gt ;" is called the infix dereference operator. In other words, it is a method that calls a subroutine whose parameters are passed by reference (among other things, of course). The arrow sign "->" can be used in a class to access functions or objects in the class.

As we mentioned above, when calling PHP functions, most parameters are passed by reference. The '->' functions in PHP are just like they are in Perl or C.

To reference the properties and methods of a class, use the -> symbol. -> means calling.

类 -> 类的成员变量或者成员函数

The left side of the "->" operator is to obtain the instance of the class, and the right side will specify and call the methods and properties of the left class.

We use sample code below to illustrate the arrow operator in php.

class 类名{ 
    $属性名1 =“属性1”; 
    $属性名2 =“属性2”; 
    function 方法名1(){ 
        ... 处理过程... 
    } 
    function 方法名2(){ 
        ...处理过程 ... 
    } 
}

Next is "instance", but this refers to an instance created from the defined class, which corresponds to the template above. If you specify the new operator and write it as classname(), an instance will be created.

In the following example, the generated instance is assigned to the variable $instance.

$instance = new 类名();

Arrow operator writing method

The arrow operator usage example is as follows.

The following code accesses "property name 1" and "property name 2"

$instance->属性名1;
$instance->属性名2;

The following code calls "method 1" and "method 2"

$instance->方法名1();
$instance->方法名2();

us Let’s look at a specific example

Let us use the arrow operator to explicitly specify the class name, attribute name, method name, processing in the method, and access each item in the above example sentence .

This time we define a Person class with its name as an attribute and introductionSelf as a method.

In addition, the __construct() that appears is a special method to be executed when using the new operator to create an instance.

// person类
class Person {
    // 名称
    $name;
    // 构造函数在实例生成的时的名称设置
    function__construct($name) {
        $this->name = $name;
    }
    // 进行自我介绍
    function introduceSelf() {
        echo "我是". $this->name ."同学".PHP_EOL;
    }
}
$taro = new Person("张三");
echo $taro->$name.PHP_EOL;
// 调用自我介绍方法
$taro->introduceSelf();

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does php arrow number mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn