Home > Backend Development > PHP Problem > What are the functions of ->, => and :: in php?

What are the functions of ->, => and :: in php?

PHPz
Release: 2023-03-05 22:02:02
forward
3020 people have browsed it

What are the functions of ->, =>,:: in php? The following article will introduce to you the functions of ->, =>,:: in php. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What are the functions of ->, => and :: in php?

Recommended: "PHP Video Tutorial"

1. -> Used for object reading classes after class instantiation properties and methods in .

For example:

class Test{
    function add(){return $this->var++;}     var $var = 0; } $a = new Test; //实例化对象名称 echo $a->add(); echo $a->var;
Copy after login

2.=>, used in arrays, the common usage is array (key=>values).

$a = array(
  '0' => '1',   '2' => '4', ); echo $a['0']; echo $a['2'];
Copy after login

3.::

Reference methods of static methods and static properties in classes
For example, static methods and static properties of classes

class Test{
    public static function test(){     public static $test = 1;    } }
Copy after login

can be used directly without instantiating objects. (The method used is class name::static method name)

Test::test(); Call the static method

test Test::$test; to obtain the value of the $test static attribute

Note: Static methods have already been instantiated and stored in memory when they read this class or import this class file. Non-static classes need to be new. Even if a static class has multiple instances in memory, there is only one copy of the static attributes.

The above is the detailed content of What are the functions of ->, => and :: in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:csdn.net
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