";]."/> ";].">
Home > Article > Backend Development > How to reference private methods internally in php
How PHP refers to private methods internally: When calling the [get()] method, add [$this] in front, the code is [$con = $this->get($name, $age);echo "my name is :".$name."
";].
How php refers to private methods internally:
This code is very simple, I want to implement the class Internal private method calls. As shown in line 4. I was used to writing JS in the past. When calling the get() method, if I didn't add "$this" in front, the program would have problems. After filling it in, you can call it.
<?php class Person { public function say($name, $age) { $con = $this->get($name, $age); //这里的$this->是关键 echo "my name is :".$name."<br />"; echo "my age is :".$age."<br/>"; echo "get :".$con."<br/>"; } private function get($a, $b) { $a = $a.$b; return $a; } } $person=new Person(); $person->say("ren", 25); ?>
Related free learning recommendations: php programming (video)
The above is the detailed content of How to reference private methods internally in php. For more information, please follow other related articles on the PHP Chinese website!