Awesome Protip! Thanks for sharing. I have added some of my own options to it and changed some others for PHP Programming, but awesome.
Don't get me wrong, I don't really mind, I see what you're saying about the private variables, but I was just asking to see what the reasons were, and that explains it :)
So what's wrong with using _self ?
Hi Nathan,
The issue I have found with phpbench is that I did a very simular test with the "foreach vs for vs while" loops and my tests differed from their results.
My foreach loop was faster than both for and while, now this came to me as a big surprise as the way that foreach works, so I got another couple of developers to check over it and they were as surprised as I was, but the results were conclusive throughout all of our tests.
So just bare in mind to not take these tests as 100% guaranteed and do your own research to ensure that they are correct.
@kanuj Then why not do something like
if( !isset( $array['email'] ) || empty( $array['email'] ) )
@mdeiters I slapped it in JSFiddle to play with: http://jsfiddle.net/XFzET/1/
It's quite cool!
@smidwap A database schema once setup correctly shouldn't need to be changed, and if it does then you should be updating the version of the software which you are 'releasing', which means you should update the code to a newer version too.
It is a well known performance issue to not use * as it takes MySQL a while enumerate which columns are in that table and if you are not using all of the data that it brings back then it is wasted time for the server to process.
If I had a table with the following columns in it:
id, username, password, email, sex, dob, city, country, avatar
and I just wanted to check whether the username exists in the database, there would be no need for me to select * when I could just select username/id.
I couldn't agree with you more on the query caching and view caching, however I did state in the start of this 'ProTip' that it was a very basic query optimisation technique and that I will be going deeper into it when I have a moment to write up a good article.
Anyway, thanks for your feedback, much appreciated!
I apologize, my Javascript really isn't up to scratch by anybodies standards, and I totally forgot you could manage "Classes" like that.
So yes, I agree with you totally there. I should have done more research into this before "jumping the gun".
Kudos.
Awesome tip, you have no idea how long I look at my server for wondering how to make my life more simple, and that is defiantly something that I will be bookmarking. Thanks!
@richthegeek It's always good to see someone who can really optimize their code effectively.
Thanks for the update as well, it's always appreciated.
I personally don't think that there is really that much in either of them, even before you optimized your code, if anything I would lean towards using your function over mine, even at the extra cost of 0.03* seconds. Solely because yours does a better job than mine does.
Good work!
@richthegeek Okay, I've done a bench mark on the two functions and mine is marginally faster than yours (tried to make the test as even as possible).
However, yours does seem to be a more thought out function which would return a better result.
------- Bench for generate_string() ------
0.84907793998718
------- </of> Bench for generate_string() ------
------- Bench for randCode() ------
0.33225393295288
------- </of> Bench for randCode() ------
Result : http://codepad.org/IQJSuY7A
@richthegeek Seems like we have a very similar function all in all. Even the purpose. I used mine to create test data as well as session IDs for my Session Class which was then MD5'd (+ salt).
I would be interested in the performance output of each to be honest. I might do a test on them and get back to you.
I Couldn't agree more with you, I wish I had mentioned this in my Pro Tip about sanitizing variables.
The only one thing I can add is HOW:
a) htmlspecialchars()
b) striptags()
c) stripslashes() / addslashes()
d) mysqlrealescapestring()
e) htmlentities()
And to be honest, hundreds of more methods of sanitizing data.
Awesome post.
Very nice function!
I might have to implement this into my current piece of work. Thanks!
@nmalcolm Brilliant, I haven't made my way through them all yet, but the ones I've seen look great!
Thank you for this, I've recently-ish moved to SublimeText2 and There were just a few things which were missing from it IMO. This has just got me the plugins that I required.
Thanks again!
I couldn't agree with you more.
Anybody who understands the OO concept should be able to separate their logic from their views. This is the basics for most systems I have worked on personally.
console.table([{name:'Gaurav', email: 'name@email.com'}, {name:'Max', email: 'name@email.net'}])
For anybody who wants the correct copy ^