Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

echo And print

By Alister Bulman

<?php echo print(1) + 2, 'b';

Thanks, I hate it….

Some explainations: print does not need parenthesis, but accepts them, and they may be part of a larger expression. In this case, the parenthesis look like belonging to print as a function, but it is actually a no operation: this leaves 1 + 2 as the only argument to print, leading to the 3 in the result.

The character in the result is 1, because print returns true after execution. Echo collects it as its first argument, but print has already displayed its result.

Finally, echo also does not need parenthesis, and it also accepts multiple arguments, separated by commas. So the final b is added at the end.

Of course, in practice, no one writes such code.

See Also

PHP Features

Last updated: 11 October 2026