1. 6
    Alternate method of calling PHP language constructs
    1m 8s

Alternate method of calling PHP language constructs

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 2 years ago

There is a difference between PHP functions and language constructs. Let's go over how to call them, and usage with & without parenthesis.

Instructor: [0:00] This a minor note, but while echo looks like a function call, it is instead considered a language construct. That is, a piece of code that makes up the PHP language. You can write this line another way. Rather than wrapping this string in parentheses, you can just eliminate them. Just leave a space between echo and the string, and the output will be exactly the same.

[0:25] There are many other language constructs, some require parentheses, and some do not. There are no performance implications of using either method, so you can use whatever you wish. You also don't need to memorize these, because I'd recommend using parentheses absolutely everywhere anyways, as it will make your code easier to read and understand.

[0:46] 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 easier to read through echo statements if they do not use parentheses.

[1:02] This is the approach I take. Everything uses parentheses besides echo.