Internal reference of private methods in PHP class, private reference of php class

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.