noidtluom Posted September 3, 2007 Share Posted September 3, 2007 Since I am trying to improve my code optimization, I have some simple questions. Is there any difference between echo (""); and echo ""; and which one is better to use? Should I use echo "$var is a very cool variable and so is $anothervar"; or echo $var ." is a very cool variable and so is ". $anothervar; or echo $var ," is a very cool variable and so is ", $anothervar; and if possible, why? Also, is there any suggestions for naming variables? I normally just name them $whatever $i $want. (of course, if the variable contains a username I name it something like $username.) So is there any sort of format that should be used? I think I read somewhere that they should be (of course, not mandatory) named like this: $twoWords or $anotherVariable, where the second word's first letter is capitalized. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 3, 2007 Share Posted September 3, 2007 That is called camelCase. It's how I prefer to name, but there are other types, if you lookup naming conventions. I would actually do this: echo $var .' is a very cool variable and so is '. $anothervar; With single quotes. If you use double, PHP has to parse the string for variables like in your first example. It's "slightly" faster, but I prefer it because it is easier for me to read. If you use a color-coded IDE you'll be able to see your strings and your variables separately, it helps in debugging. Quote Link to comment Share on other sites More sharing options...
noidtluom Posted September 3, 2007 Author Share Posted September 3, 2007 Thank you. With single quotes. If you use double, PHP has to parse the string for variables like in your first example. It's "slightly" faster, but I prefer it because it is easier for me to read. I'm sorry I didn't really understand your sentence. Which one is faster, the " or ' ? and which one do you think is easier to read? I got confused with the use of "it" in your sentences. Have you also got an answer for the difference between echo (""); and echo ""; ? and which should be used? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
btherl Posted September 3, 2007 Share Posted September 3, 2007 Single quotes are faster than double quotes, because single quoted strings don't need to be examined by php. But double quotes strings may contain variables, so php has to check for that first. My syntax highlighter (vim) highlights variables inside double quotes. Regarding echo, it doesn't matter. Even if there is a speed difference there, it'll be too small to matter. Both act the same way. Quote Link to comment 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.