p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: to ( ) or not to ( )...


Message #1 by "Darin" <warlock_1300@y...> on Thu, 7 Feb 2002 17:16:53
I have started learning PHP4 in the last few weeks and in the wrox book I 

am using there are of course several occassions where an 'echo' command is 

used. However, where my confussion and subsequent question comes from is 

this:

  The echo command is used with and without parenthesis. It is not 

explained in the book why at times they are used sometimes and other times 

not. I can not garner from the code ( I'm a newbie with PHP ) as to a 

posible why either. so my question is... Is there a 'Why' when using () in 

an echo command and if so please explain. I apreciate the time and effort 

of any replies. Thank you.
Message #2 by "Nikolai Devereaux" <yomama@u...> on Thu, 7 Feb 2002 10:26:53 -0800

from php.net/echo



echo() is not actually a function (it is a language construct) so you are

not required to use parentheses with it. In fact, if you want to pass more

than one parameter to echo, you must not enclose the parameters within

parentheses.



I ususally don't use parens with echo.

I do use them with print().  According to the manual, echo can accept

multiple parameters (in which case you must NOT use parens) whereas print

cannot.



Also, I don't generally pass more than one parameter to echo.  If there are

many things I need to print, I usually just rely on variable substitution or

string concatenation. e.g.:



$name = "Nikolai"

echo "Hello, $name.";

echo 'What's new and exciting in the world, ' . $name . '?';



Take care,



$name



:)





-----Original Message-----

From: Darin [mailto:warlock_1300@y...]

Sent: Thursday, February 07, 2002 5:17 PM

To: beginning php

Subject: [beginning_php] to ( ) or not to ( )...





I have started learning PHP4 in the last few weeks and in the wrox book I

am using there are of course several occassions where an 'echo' command is

used. However, where my confussion and subsequent question comes from is

this:

  The echo command is used with and without parenthesis. It is not

explained in the book why at times they are used sometimes and other times

not. I can not garner from the code ( I'm a newbie with PHP ) as to a

posible why either. so my question is... Is there a 'Why' when using () in

an echo command and if so please explain. I apreciate the time and effort

of any replies. Thank you.




$subst('Email.Unsub').




  Return to Index