the-botman Posted December 4, 2009 Share Posted December 4, 2009 hi guys .. is this statment right? $url = "http://www.site.com/soccer/.$_GET['league']."; Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/ Share on other sites More sharing options...
salathe Posted December 4, 2009 Share Posted December 4, 2009 Try it and see. Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971167 Share on other sites More sharing options...
KevinM1 Posted December 4, 2009 Share Posted December 4, 2009 To be safe, you should put your $_GET variable in curly braces to ensure it's handled correctly, like so: $url = "http://www.site.com/soccer/{$_GET['league']}"; Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971174 Share on other sites More sharing options...
shedokan Posted December 4, 2009 Share Posted December 4, 2009 To be safe, you should put your $_GET variable in curly braces to ensure it's handled correctly, like so: $url = "http://www.site.com/soccer/{$_GET['league']}"; Why not just use? : $url = 'http://www.site.com/soccer/'.$_GET['league']; A lot cleaner, simpler and a bit faster. Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971176 Share on other sites More sharing options...
MadTechie Posted December 4, 2009 Share Posted December 4, 2009 Its very slightly fast 100th of a second but IMHO I find Nightslyr solution cleaner as I find it quicker to update later (that saves me a little longer that a 100th of a second Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971182 Share on other sites More sharing options...
shedokan Posted December 4, 2009 Share Posted December 4, 2009 What do you mean by "quicker to update later"? Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971184 Share on other sites More sharing options...
MadTechie Posted December 4, 2009 Share Posted December 4, 2009 I find that if i start with this $url = 'http://www.site.com/soccer/'.$_GET['league']; this takes me longer $Domin = "site.com"; $Section = "soccer"; $url = 'http://www.'.$Domin.'/'.$Section.'/'.$_GET['league']; than if i start with this $url = "http://www.site.com/soccer/{$_GET['league']}"; and update do this $Domin = "site.com"; $Section = "soccer"; $url = "http://www.$Domin/$Section/{$_GET['league']}"; //or $url = "http://www.{$Domin}/{$Section}/{$_GET['league']}"; and I find it slightly easier to read! but with any micro optimization it normally depends on the personal preference. My Logic is simple, if its a hundredth of a second faster at run time but takes 2 seconds longer to read a design time I'll probably not worry about the hundredth of a second. Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971201 Share on other sites More sharing options...
shedokan Posted December 4, 2009 Share Posted December 4, 2009 Ok ok, sorry for making you mad! It's just that I didn't understand your logic, and your'e right depends if the person is a speed freak or not. but you have to agree that if it's a giant slow application so then you would try to make it faster with these things. Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971207 Share on other sites More sharing options...
KevinM1 Posted December 4, 2009 Share Posted December 4, 2009 Ok ok, sorry for making you mad! It's just that I didn't understand your logic, and your'e right depends if the person is a speed freak or not. but you have to agree that if it's a giant slow application so then you would try to make it faster with these things. I don't think that MT is mad. Also, if my app is running slowly, looking at how my output was interpolating variables would be one of the last steps I'd take, simply because there are other things that would be the likely source of the slowdown. Not saying that you wouldn't, either, it's just that there's a common meme with some users on here where they think that code optimization (which shouldn't be a priority until the late stages of a project) consists simply of fiddling around with how output strings are quoted and concatenated because some book or tutorial mentions that one way of doing it is 'faster' (hundredth's of a second, if that) than another. All while they have nested loops running amok everywhere. Again, not lumping you, specifically, in that group. Just figured I'd comment on a general trend I've seen in order to help curb things in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971223 Share on other sites More sharing options...
MadTechie Posted December 4, 2009 Share Posted December 4, 2009 Sorry if I appeared mad, that was not my intent, I just find if I have a lot of HTML in 1 of more variables I know I'm probably going to update it later, so I use the logic of single quotes for strict and double quotes for dynamic, for the whole variable. then I just have to remember to escape the double quotes, for example in $_GET['league'] league is strict (won't change) but $_GET["league{$x}s"] is dynamic and LOOK's cleaner (to me) instead of $_GET['league'.$x.'s'] as I said it's down to personal preference really. Oh and I maybe mistaken but I believe the biggest difference in speed was in PHP4 but was optimised in PHP5. in a loop of 10,000 the difference was 0.03 seconds EDIT: that's $url = 'http://www.site.com/soccer/'.$_GET['league']; winning by 0.03 seconds Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971233 Share on other sites More sharing options...
shedokan Posted December 4, 2009 Share Posted December 4, 2009 Your'e right that there are other things that slow down a lot more than using single-quote instead of double-quotes. And for me speed always comes first but that doesn't means that I'm going to write all of my code in one line so it will be "faster", I'm going to write it in a way that I can easily understand it, and the architecture of the app is a lot more crucial than a hundredth's of a second. But in apps that need to run the fastest and are loading in 200ms so cutting it down to 150ms counts a lot, one day I'll post loading times of my online OS(an app where speed counts) with small optimisations and small ones and I'm sure there would be a big difference. And your'e right I think $_GET["league{$x}s"] is a lot cleaner, maybe working too much on a speedy app has made me blind. lol well I think I have pulled away from the subject(which is already solved) too much. Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971251 Share on other sites More sharing options...
MadTechie Posted December 4, 2009 Share Posted December 4, 2009 well I think I have pulled away from the subject(which is already solved) too much. echo "Agreed"; I mean echo 'Agreed'; Quote Link to comment https://forums.phpfreaks.com/topic/183972-is-this-statment-right/#findComment-971255 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.