PHP implements tests on var_dump and echo output multi-variables

小云云
Release: 2023-03-22 15:54:01
Original
2196 people have browsed it

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 = &#39;a&#39;;
	private $d = &#39;d&#39;;
	public function sayHello(){
		echo &#39;Hello &#39;;
	}
}


class B{
	public $b = &#39;b&#39;;
	public function sayHello(){
		return &#39; world !&#39;;
	}
}


class C extends B{
	use A;


	public $b = &#39;c&#39;;
	
}
var_dump(5,7,(new C)->sayHello(),aac(4,5),&#39;<br />&#39;);


echo 5,7,(new C)->sayHello(),aac(4,5),&#39;<br />&#39;;


function aac($a,$b){
	echo &#39;<hr />&#39;;
	echo $a,$b;
	echo &#39;<hr />&#39;;
	echo $a+$b;
	echo &#39;<hr />&#39;;
	return $a+$b;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template