LiamProductions Posted July 23, 2007 Share Posted July 23, 2007 Hey. What do you use more ' or " in coding for example echo 'Hello'; echo "Hello"; Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/ Share on other sites More sharing options...
effigy Posted July 23, 2007 Share Posted July 23, 2007 I use the right tool for the job: singles if literals are involved; doubles if interpolation is the case. These rules do not apply when multiple escapes would be required, thus uglifying the code. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-305568 Share on other sites More sharing options...
LiamProductions Posted July 23, 2007 Author Share Posted July 23, 2007 so you use ' ? Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-305632 Share on other sites More sharing options...
effigy Posted July 23, 2007 Share Posted July 23, 2007 I use single quotes if I'm creating a literal: $name = 'Bob'; I use double quotes if I'm interpolating: echo "name = $name"; And I ignore these rules to avoid ugly backslashings: echo "That's Bob's pencil!" Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-305704 Share on other sites More sharing options...
The Little Guy Posted July 23, 2007 Share Posted July 23, 2007 I use ' 90% of the time $name = 'Tim'; echo 'my name is joe'; echo 'my name is '.$name; echo 'it\'s time for school'; include "/my/include.php"; header("Location: /index.php"); I don't know why I do it like that either. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-305765 Share on other sites More sharing options...
ober Posted July 23, 2007 Share Posted July 23, 2007 I use the right tool for the job: singles if literals are involved; doubles if interpolation is the case. These rules do not apply when multiple escapes would be required, thus uglifying the code. One is not better than the other. It's a question of when you use them. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-305825 Share on other sites More sharing options...
JayBachatero Posted July 23, 2007 Share Posted July 23, 2007 I used ' most of the times except when I must use ". Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-305833 Share on other sites More sharing options...
utexas_pjm Posted July 24, 2007 Share Posted July 24, 2007 I read somewhere that using single quotes is actually slightly more efficient than using double quotes because when using double quotes the PHP engine must process the string in order to check for, and possibly evaluate, any variables which may be included in the string. I can't personally speak to the validity of this claim, but it does make sense from a theoretical standpoint. I'm quite certain that any performance hit incurred by using double quotes is negligible in most circumstances --but it is something to consider none the less. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306010 Share on other sites More sharing options...
Azu Posted July 24, 2007 Share Posted July 24, 2007 Hey. What do you use more ' or " in coding for example echo 'Hello'; echo "Hello"; I use ' whenever I don't need to put any variables in it, because ' is faster then ". I use " when I need to use a variable, because using " with a variable is faster then using '.$variable.'. I base all of my programming decisions purely on speed/efficiency. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306039 Share on other sites More sharing options...
fert Posted July 24, 2007 Share Posted July 24, 2007 i use " Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306188 Share on other sites More sharing options...
LiamProductions Posted July 24, 2007 Author Share Posted July 24, 2007 Well i use " but now i've started to use ' because alot of functions i've seen on PHP use ' for example: echo date('d'); Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306191 Share on other sites More sharing options...
trq Posted July 24, 2007 Share Posted July 24, 2007 Well i use " but now i've started to use ' because alot of functions i've seen on PHP use ' for example: echo date('d'); Which will also accept... <?php echo date("d"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306260 Share on other sites More sharing options...
effigy Posted July 24, 2007 Share Posted July 24, 2007 I read somewhere that using single quotes is actually slightly more efficient than using double quotes because when using double quotes the PHP engine must process the string in order to check for, and possibly evaluate, any variables which may be included in the string. I can't personally speak to the validity of this claim, but it does make sense from a theoretical standpoint. I'm quite certain that any performance hit incurred by using double quotes is negligible in most circumstances --but it is something to consider none the less. Agreed. And not only is it (arguably) more efficient for PHP, but (I think) also more efficient for the programmer. Imagine you're trying to debug a script with thousands of lines of code. Every time you see double quotes you'll have to spend extra time analyzing the string (just like PHP) because it's possible that something could be sneaking in there and, as a result, being interpolated. If single quotes are being used then you immediately know a literal is involved. Again, in my opinion, it's about using the right tool in the right context. PHP gave us both, so use them as they're intended. You wouldn't buy a tool set and always use a wrench for driving nails and ignore the hammer, even though they both work. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306291 Share on other sites More sharing options...
LiamProductions Posted July 24, 2007 Author Share Posted July 24, 2007 Well i use " but now i've started to use ' because alot of functions i've seen on PHP use ' for example: echo date('d'); Which will also accept... <?php echo date("d"); ?> Yes, I know, But PHP.net use ' for that kind of stuff. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306372 Share on other sites More sharing options...
Mutley Posted July 24, 2007 Share Posted July 24, 2007 I use " when doing things like echo/text, then ' for variables, numbers and whatever else. Not sure why, just looks tidy. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306373 Share on other sites More sharing options...
LiamProductions Posted July 24, 2007 Author Share Posted July 24, 2007 I use them the way i first learn how to use them... I use to use " for echo's ect... but now im starting to pick up the habit of using a ' Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306390 Share on other sites More sharing options...
Azu Posted July 26, 2007 Share Posted July 26, 2007 Don't use quotes for integers it will turn them into strings! And single quotes won't work for variables. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-308434 Share on other sites More sharing options...
LiamProductions Posted July 27, 2007 Author Share Posted July 27, 2007 Single qoutes do work for Variables. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-308816 Share on other sites More sharing options...
Azu Posted July 27, 2007 Share Posted July 27, 2007 <?$a=1; echo'$a';?> Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-309228 Share on other sites More sharing options...
LiamProductions Posted July 28, 2007 Author Share Posted July 28, 2007 <?$a=1; echo'$a';?> Try: <?php $a= 1; echo $a; ?> Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-309660 Share on other sites More sharing options...
Daniel0 Posted July 28, 2007 Share Posted July 28, 2007 <?$a=1; echo'$a';?> Try: <?php $a= 1; echo $a; ?> Duh... where are the single-quotes in your script? You said they'd work with variables... Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-309676 Share on other sites More sharing options...
LiamProductions Posted July 28, 2007 Author Share Posted July 28, 2007 Oh... I didn't realise he ment like that. Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-309699 Share on other sites More sharing options...
Azu Posted July 30, 2007 Share Posted July 30, 2007 <?$a=1; echo'$a';?> Try: <?php $a= 1; echo $a; ?> That's not single quotes OR double quotes. That's good old fashioned integers Quote Link to comment https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-310750 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.