Search code examples
phpvariablestypesecho

Does echo cast non-string variables into string type on the fly?


I've just came across this post mentioning that echo can only print string(s), that's why we cannot print the full array. But, we can easily echo integers and floats etc like this:

$int = 3;  $float = 3.456;  
echo $int, "</br>", $float;

I was just wondering does echo cast these variables to string type behind the scenes?

Thank you.


Solution

  • Per the section on Converting to string from the manual:

    String conversion is automatically done in the scope of an expression where a string is needed. This happens when using the echo or print functions, or when a variable is compared to a string.