Search code examples
phplanguage-features

PHP hidden trick or a supported feature?


I know that to concatenate strings in php, a dot should be used:

echo 'hello' . ' world'; // hello world

But incidentally i typed this:

echo 'hello' , ' world';

and the result was still hello world without any errors.

Why is it so? Can we also concatenate using comma?


Solution

  • It's documented in the entry for echo:

    void echo ( string $arg1 [, string $... ] )

    The two forms are not actually equivalent, since there's a difference in the instant in which functions are evaluated.