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

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

PHPz
PHPzforward
2020-09-25 14:10:022983browse

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;

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

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

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;    } }

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete