Home > Backend Development > PHP Tutorial > Let's talk about the usage of arrow symbol (->) in php

Let's talk about the usage of arrow symbol (->) in php

PHPz
Release: 2023-04-11 12:36:01
Original
2614 people have browsed it

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!";
   }
}
Copy after login

To access the properties or methods of this class, we need to instantiate an object first:

$person = new Person();
Copy after login

Now, we can access it through arrow symbols Properties and methods of this object:

echo $person->name;
$person->age = 30;
$person->sayHello();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template