Internal reference of private methods in PHP class, private reference of php class
I used to get used to art and front-end development. Now, I am going to learn PHP at the advanced backend. When I was learning the class, I encountered a private method call problem.
The Code is as follows:
1 <? Php 2 class Person {3 public function say ($ name, $ age) {4 $ con = $ this-> get ($ name, $ age ); // here $ this-> is the key 5 echo "my name is :". $ name. "<br/>"; 6 echo "my age is :". $ age. "<br/>"; 7 echo "get :". $ con. "<br/>"; 8} 9 private function get ($ a, $ B) {10 $ a = $. $ B; 11 return $ a; 12} 13 14} 15 16 $ person = new Person (); 17 $ person-> say ("ren", 25 ); 18 19?>
This code is very simple. I want to call private methods inside the class. As shown in row 4th. I used to write js in the past. when calling the get () method, I didn't add "$ this" to the front, and the program encountered problems. You can call this function after completing the configuration.