Home > Article > Backend Development > PHP implements tests on var_dump and echo output multi-variables
This article mainly shares with you the PHP implementation of multi-variable testing of var_dump and echo output. It is mainly shared with you in the form of code. I hope it can help you.
<?php trait A{ public $a = 'a'; private $d = 'd'; public function sayHello(){ echo 'Hello '; } } class B{ public $b = 'b'; public function sayHello(){ return ' world !'; } } class C extends B{ use A; public $b = 'c'; } var_dump(5,7,(new C)->sayHello(),aac(4,5),'<br />'); echo 5,7,(new C)->sayHello(),aac(4,5),'<br />'; function aac($a,$b){ echo '<hr />'; echo $a,$b; echo '<hr />'; echo $a+$b; echo '<hr />'; return $a+$b; }
Print result:
Hello
##45
9
int(5) int(7) NULL int(9) string(6) "
" 57Hello
45
9
9
Summary:
var_dump The PHP documentation description mentions: It is the same as outputting the results directly to the browser. You can use output control functions to capture the output of the current function and then (for example) save it to a string. In other words, var_dump will execute multiple variables or multiple expressions, cache the intermediate process output, and finally output them together. A simple understanding is that if there are calls and expressions output in var_dump, the output of the intermediate processes of these calls or expressions will be output first from left to right, and the results will be output last. And echo executes and outputs multiple variables, expressions, and calls from left to right. Related recommendations:php var_dump code application for traversing object attributes
The above is the detailed content of PHP implements tests on var_dump and echo output multi-variables. For more information, please follow other related articles on the PHP Chinese website!