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 2 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.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today