objnoob Posted September 12, 2010 Share Posted September 12, 2010 Is it more efficient to concat strings to variables or include variables within a double quote enclosed string? I've created a couple of classes to help take tons of coding off of the front end, and I've been pondering the idea of creating a container class to hold specific objects of some classes. My container class methods will do a lot of iterating through a lot of varient object names, and I'm questioning efficiency in regards to resolving the object variable's names... Which is more efficient? ${"type_$i"}->setAttribute('readonly', 'readonly'); ${'type_'.$i}->setAttribute('readonly', 'readonly'); Quote Link to comment https://forums.phpfreaks.com/topic/213239-efficiency-to-i-or-to-i/ Share on other sites More sharing options...
premiso Posted September 12, 2010 Share Posted September 12, 2010 Concat will be more efficient. But the difference is so small will not be noticeable. The reason being is that single quotes do not have to worry about parsing data so it is one less look up needed. Quote Link to comment https://forums.phpfreaks.com/topic/213239-efficiency-to-i-or-to-i/#findComment-1110326 Share on other sites More sharing options...
ignace Posted September 13, 2010 Share Posted September 13, 2010 The reason being is that single quotes do not have to worry about parsing data so it is one less look up needed. So the below is slower because you used double quotes Basically, it doesn't matter use whatever you fancy! And even if you run into performance issues this will not be one of those area's you'll be putting focus on. ${"type_".$i} Quote Link to comment https://forums.phpfreaks.com/topic/213239-efficiency-to-i-or-to-i/#findComment-1110487 Share on other sites More sharing options...
premiso Posted September 14, 2010 Share Posted September 14, 2010 So the below is slower because you used double quotes ${"type_".$i} Correct. And as I said, the difference is so small that it will not be noticeable, but the bottom line is that double quotes are slower. Quote Link to comment https://forums.phpfreaks.com/topic/213239-efficiency-to-i-or-to-i/#findComment-1111106 Share on other sites More sharing options...
Mchl Posted September 14, 2010 Share Posted September 14, 2010 THe bottommost line is, something is wrong with this code, that looks like could use arrays instead of variable variables. Quote Link to comment https://forums.phpfreaks.com/topic/213239-efficiency-to-i-or-to-i/#findComment-1111108 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.