Is it possible to concatenate "null" with a string in PHP?

I did not find a statement about string and null compatibility in documents, but tried this in PHP 5.5:

 echo 'foo' . null . 'bar'; 

prints foobar .

I wonder if this behavior is guaranteed or “safe” (in SQL, for example, this is not so)? Or ask for another way: should I ever check for null before concatenating strings? how

 echo 'foo' . (($mystring === null) ? '' : $mystring) . 'bar'; 
+6
source share
1 answer

In the documentation:

NULL is always converted to an empty string.


Yes, you can rely on this behavior.

+17
source

All Articles