skew Posted July 26, 2011 Share Posted July 26, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/242851-multiple-ways-to-invoke-echo/ Share on other sites More sharing options...
premiso Posted July 26, 2011 Share Posted July 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242851-multiple-ways-to-invoke-echo/#findComment-1247352 Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2011 Share Posted July 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242851-multiple-ways-to-invoke-echo/#findComment-1247354 Share on other sites More sharing options...
skew Posted July 26, 2011 Author Share Posted July 26, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/242851-multiple-ways-to-invoke-echo/#findComment-1247366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.