The magic tricks, We all are aware of the way to make dates look cool and numbers look awesome. But there are a few things which most people don’t think about, and I’m one of them. As I started working on this article, I did a little R & D and found a few things which will make me change the way why I use PHP. Let’s dive right in for further details!
1) Validating Partially the Email Addresses before doing any hard work
PHP has an inbuilt function called checkdnsrr() which will take an email address and check if it resolves as an IP address. This is very cool for example when we are sending emails. checkdnsrr() should return false while you are trying to send an email with this function, and you can return an error notifying the user that domain probably doesn’t exist before you do anything else. This is great that you didn’t really even have to validate the email address in any other way, saving you server resources, time, and just making things really better. Of course, you should do the usual slog and validate with filters, but this is a good way to actually see of the domain and email address actually exist.
2) You don’t always need the closing PHP Tag
It’s true. In fact, Zend Framework forbids it. PHP does not require you to close a PHP tag that is at the end of a file or is in a file that contains the only outsource PHP development. In other words, you don’t need the ‘?>’ until there is a need to use the non-PHP code after some PHP. Accustom leaving it out, leaving it in can cause problems in certain circumstances, and it has to do with leaking whitespace after the closing tag and causes chaos when you output XML.
3) MySQLI
If you haven’t used mysqli yet, you really need to start thinking about it. During a project, Mysqli takes the basic mysql functions that you usually end up rewriting 500 times, or if you are more inventive, you are creating functions for and lays them out on a table for you – ready to use. Mysqli makes database transactions easy because of the hard work done. Start using it, you won’t be sorry.
4) Switch Off Error Reporting. Seriously
When you go to production on your website, killing the error reporting. You don’t want to put all your errors and warnings out there for all mankind to see. Just simply set error_reporting(0), and all is well with the world.
5) Comment Comment Comment
You should comment your code if you don’t then no one is going to take you seriously as a developer until you do. It’s that very simple.
6) Validate
Validation is not only important, but it should also be mandatory. You need to validate all the inputs, and outputs, and hence make sure that the code you are using is the best possible code it can be. There is nothing else more important.
7) Code Every Day, Build Real Things
Ruby on Rails, was created by David Hanson, after extracting the work from Basecamp, a project that he insists he was able to do because he developed it in anger. What does this means, that he developed something real and tangible that people would use? By thinking like this, he made it in the best way he knew how to. You need to do the same. Developing an application which, doesn’t do anything and is never going to be used by anyone, is not going to make you great. Building something which you know has to work, has to influence or WOW people, and make people want to pay to use it or buy it that WILL make you great. At the very least it will make you learn something.