Jump to content

Recommended Posts

I had just discovered that the echo works also like a function. Here an example:

echo("Hello World!");

 

Normally and in many books I see it this way:

echo "Hello World!";

 

What's the difference between both lines? Does the second line points to the same physically location as the first one it does?

 

Link to comment
https://forums.phpfreaks.com/topic/242851-multiple-ways-to-invoke-echo/
Share on other sites

Same physically location?

 

The difference is the () parans. They are not required and not needed. There is no difference as it does the same thing with the same performance. I prefer the non-paran method. Example of echo using parameters: (*Edit Note) With the exception that you cannot pass parameters to echo when it is encased in parans.

 

echo "Test", $one, $two;

 

Both do the same thing, no difference in execute time, just one has parans around it.

 

EDIT:

Removed some incorrect information.

echo

(PHP 4, PHP 5)

 

echo — Output one or more strings

 

Description

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

Outputs all parameters.

 

echo() is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo() (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo(), the parameters must not be enclosed within parentheses.

 

 

With the same physically location I mean the location in the API of PHP. When both of the two lines of code do the same, then it must be one and only one "function". It would be strange if

echo "blah";

is not the exactly the equivalent of the following:

echo("blah");

 

In summary, it doesn't make a difference which invocation style I use or prefer?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.