Alternate method of calling PHP language constructs

This is a minor note, but while echo looks like a function call, it is actually instead considered a language construct — that is, a piece of code that makes up the PHP language.

You can actually write this line another way.

<?php
echo('Hello world!');

Rather than wrapping the string in parentheses, you can eliminate them! Just leave a space between echo and the string.

<?php
echo 'Hello world!';

There are many other language constructs. Some require parentheses, some do not.

Screen Shot 2022-02-24 at 10.03.34 AM.png

There are no performance implications of using either method, so you can use whatever you wish. You don’t need to memorize these, because I’d recommend using parenthesis absolutely everywhere anyways, as it will make your code easier to read and understand.

There is one exception though, and that is probably the echo construct. Since this construct is used so often and usually deals with outputting strings, I’d say it’s actually easier to read through echo statements if they do not use parentheses. So, this is the approach I take: everything uses parentheses besides echo.

Extra lesson content locked
Enroll to access source code, comments & track progress.
Enroll for Free to Unlock