Home > Article > Backend Development > Let's talk about the usage of arrow symbol (->) in php
PHP arrow (->) is a symbol used for object access. In PHP, an object is a collection of properties and methods. Arrow symbols allow developers to access and manipulate these properties and methods.
In PHP, objects can be created by instantiating a class, and then using arrow notation to access the object's properties and methods. For example, here is a simple PHP class:
class Person { public $name; public $age; public function sayHello() { echo "Hello!"; } }
To access the properties or methods of this class, we need to instantiate an object first:
$person = new Person();
Now, we can access it through arrow symbols Properties and methods of this object:
echo $person->name; $person->age = 30; $person->sayHello();
In the above code, arrow symbols are used to access the properties $name and $age of the $person object, and the method sayHello().
It should be noted that arrow symbols can only be used to access the properties and methods of objects. If we want to access a static property or method of a class, we need to use two colons (::) instead of arrow symbols.
In PHP development, the arrow symbol is a very common symbol. Understanding its meaning and usage can help developers better understand and manipulate objects.
The above is the detailed content of Let's talk about the usage of arrow symbol (->) in php. For more information, please follow other related articles on the PHP Chinese website!