It is not that echo changes the type of anything.
echo() is a language construct whose parameters will be processed as strings. Thus, he expects a bite when each parameter is passed to him.
PHP at the language level, however, has no problems with manipulating data types, since it is a dynamic, freely typed language (like Lisp or Perl, and compared to the strict Python or C type).
So, even if (almost) 1 everything you say is basically an expression, each of these sentences has a return value.
Each value has its own type. Say, for example, that 4 is an integer value. This will always be true. So, if you check the integrity of the type, isint(4) will always return true (like boolean ).
However, the approach in PHP is that it should be a language that takes care of progressing to the necessary types at runtime, and not that the programmer should think about the types of variables that can even be changed in some use cases (e.g. , general quick sort function).
Thus, whenever you use an expression as part of another, there is a type inference process by which each subexpression advances to the deduced type (part of a partial expression that has already been parsed).
So let's say we have the expression "13" . 37 "13" . 37 . In PHP . is a string concatenation operator. "13" is an expression of type string . So, the right operator . must be a string. Since this is not the case, the Zend Engine is looking for an easy way to push the 37 integer expression into a string. He finds one: the string "37" generated by the expression C printf("%d", value) .
The same thing happens with any data type. This can be somewhat troubling in advanced programming topics, since it is not always necessary to simply check the value of an expression, but also its type, since automatic type promotion can lead to a truth value that a naive programmer might have left uncontrollable without dealing with expression types .
This is especially true in environments such as the following:
if ($anything == 6) { } elseif (!$anything) { } elseif (is_string($anything)) { } elseif ($anything == true) { }
If you are looking for an ASCII byte representation, use chr ()
1 There are exceptions, such as the namespace construct, the declare construct, this is not Lisp: -D