What is the difference between PHP5 and PHP7 about getting functions?
This article focuses on "what is the difference between PHP5 and PHP7 about getting functions". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the difference between PHP5 and PHP7 about getting functions?"
The difference between PHP5 and PHP7 in taking array elements as dynamic function names
When you execute a function / method by getting the function / method name through variables in PHP5 and PHP7, the same code may not run because of the interpretation policy that does not agree between versions.
Example
$a = ['add',' sub']; class Test {public function add () {echo 1 + 2;}} $t = new Test (); $t-> $a [0] ()
The above example works normally under PHP5.6, but throws Fatal error: Function name must be a string under PHP7. This is because when t-> t − > a0 is executed under PHP5, $a [0] is executed first, the value of the element is obtained, and then the specific method of the object is executed.
Under PHP7, t-> t − > a will be executed first, causing an error to be thrown and interrupting execution. If you need to execute normally under PHP7, you need to change it to t-> {a [0]} ().
For specific differences, please refer to:
At this point, I believe you have a deeper understanding of "what is the difference between PHP5 and PHP7 about getting functions". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!