Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-305825
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306010
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306039
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/61397-do-you-use-or/#findComment-306291
Share on other sites

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.