Most people who start to get the hang of PHP feel like they can do anything. It literally took me 5 days until I was writing PHP professionally. That's how fast and easy it is to get great results with PHP. But there's a distinction between the developer who could get the job done poorly with some Googling and 5 hours of time and the true professional who spent the extra time developing the habits that set him apart from the herd.
Programming should always be results oriented, and with PHP that's easy because it's so simple to get results. However, if you're writing more than an about page it's important to realize how your results are going to suffer if you don't put in the effort to make flexible, stable code that other developers can work on or take over. That's why you haven't learned PHP if you haven't learned how to do it right.
PS. If you missed it, you can find part one here: Learning PHP the Right Way From the Start
PHP doesn't care about spacing or indenting. Some times it doesn't even care if you put code in curly braces when you're supposed to. This can be very important for putting PHP inside of an HTML file, however it can be very annoying when somebody else's code is hard to read. You should almost never have more than a single PHP statement on one line, you should always indent code that goes in curly braces, and you must absolutely and always use curly braces for if statements, loops, or any other place that you can use them. Also, you should write a comment explaining what the next few lines of code does in a short sentence every few lines, and always write a comment explaining what a method does. Make this a habit that you never break, even when you think no one is ever going to see your code or that you're never going to look at the code again. Every time you don't follow these practices you become a little more stupid in that you aren't taking an opportunity to reinforce a habit that should always be exercised. If you don't develop this habit, you will never be any good. It is that important.
You can often see people asking for a developer who can do OOPHP like it's a different thing than PHP. For their intents and purposes it is. It is one of the most important distinctions between doing PHP and doing PHP right. OOPHP stands for object-oriented PHP, and using it makes a world of difference from simply adding some PHP into an HTML document.
If you are writing your website in a framework, and you'd better be, you'll notice that a lot of PHP code gets written for classes in files that don't have any HTML. This type of a framework is called a Model View Controller (MVC) framework, and most frameworks follow this format. The idea is to put as much PHP code as you possibly can into classes (the controllers) that use other classes to do all of the talking to the database (the models) to make complete HTML files using parts of HTML and JavaScript from several templates and widgets (the view). This organization is industry standard, and is often the best way to organize your PHP, HTML, and SQL.
Classes can get very complicated, but starting off is easier than you may think. To create a class you simply type:
class myClass {
function myFunction {
echo “Hi”;
}
}
To use this function you can make a variable out of the class called an object and use the object by typing “$myObject = new myClass; $myObject->myFunction();”, or you can call the function directly by typing “myClass::myFunction();”. Those are the basics. Probably took you a few seconds to learn. Now there are loads of cool things that PHP can do with classes that will take you some time to learn, and learning is best through practice or on the job. It will come to you as you practice and progress as a developer. Look through the PHP manual, Googling guides and help forums, asking questions on Stack Overflow, or looking at someone else's code. For right now just take the time and extra effort to learn the habit of placing as much code as possible in classes remembering these two guidelines:
The third thing most new PHP developers neglect to learn that separates good programmers from bad ones is unit testing. The first web application I worked on that used unit testing was the first time I had even heard the phrase “unit testing” and it was not only embarrassing, it literally hurt my career. You don't really need unit testing to be a PHP developer that's good at making small websites, but you can't claim to be a web application developer until you at least know how to do unit tests.
In PHP the two most common unit testers are PHPUnit and SimpleTest. What unit testers do is give you some classes and functions that will help you write code to make sure that your other code does what it's supposed to. Once you get over the learning curve it's very easy, and makes you a better human being. If you will form the habit of making tests any time you want to check if PHP is doing what you want it to other developers will like, love, and trust you.
PHP has an interesting community of developers because there are two classes of PHP developer. A script kiddy that can write some PHP in his HTML page, great for a designer who fears computers without an apple on the case, and real PHP programmers that other developers will want to work with and hire. Writing code that looks good, using objects, and using tests are what sets a developer apart from a script kiddy, and if you're planning on learning PHP you should take a little bit of extra time to learn how to do those things. If you simply can't put in this extra effort, or you're afraid of doing something wrong, then I would strongly suggest you purchase a service like Lexy so that you can leave these extra things to those of us who work full time on improving our web development skills while you worry about the other things that make a good website.
There is a lot more to do if you want to become a six figure developer some day, and there are plenty of developers who's primary function involves PHP code who make that much, but of all the things that a PHP rockstar must master these three are the paths with the most common pitfalls. Mostly because a developer will get lazy and avoid writing tests when he should; write code that doesn't fit in a framework because he's in a hurry; put something in a class it doesn't belong or worse, in no class at all; or write code that other developers can't easily work on because he is a despicable human being and a disgrace to the human race. I'm joking (mostly), but even though many developers occasionally commit these sins, if you want to be any good you will walk the righteous path and make others embarrassed when they see the 1337 code.
VivaNet2.0 constructed website, myUSAi.org according to our exact technical specifications and with our required timeframe and budget. We liked VivaNet2.0...