in php ->, =>, ::, $ this-> use with the scene

A, -> used to refer to a class attribute (variable), the method (function)

You can -> understood as meaning calls

<?php

Class a{

Var $id;
Function add(){
  $this->id=”test”;
  echo “abc”;
  }
}
B $ = new new a;
 $ B -> add ();   // call to a class of add () method, the output of ABC 
the Echo  $ B -> id; // attribute id of a call class, output Test 
? >

II => is used to define an array with

of arr1 $ = Array (0 => 'PHP',. 1 => 'IS', The => 'The' );
 the Echo  $ ARRA [0], $ of arr1 [. 1], $ ARR [ 'The'];    // values corresponding output settings

III :: used to directly call the class property or method, without instantiating

Normal circumstances we instantiate a way to call class properties or methods, but may not need to use :: instantiate an object, you can call directly.

such as:

<?php
Class abc{
Var $name=”xiaoming”;
Function is_name(){
Echo 'xiaoming is good';
}
}
// direct call: 
Echo abc :: is_name (); // output test isgood

Four, $ this-> indicates that the call specific objects instantiated

 We generally use the class property or method within a class, use $ this->

<?php
Class abc{
Var $name;
Function is_name(){
Echo $this->name;
}
}
name1 $ = new new ABC;
 $ name1 -> name = 'assigned to name1' ;
 $ name1 -> is_name (); 
 // output is assigned to name1

Guess you like

Origin www.cnblogs.com/xiong-hua/p/12052838.html