Ask HN: How to write great PHP code?
6 comments
I'd suggest choosing one of the many MVC frameworks for PHP (http://www.phpframeworks.com/) and reading that framework's tutorials and guides then getting to work on a real project.
For example, there's a series of tutorials for Yii (http://www.larryullman.com/series/learning-the-yii-framework...) as well as an intro to the concepts behind the MVC pattern (http://www.larryullman.com/2009/10/08/understanding-mvc/)
First, make sure you understand some of the higher level OO concepts of PHP like variable scope, inheritance, polymorphism, and visibility. You can easily do this in the php docs and stackoverflow, or other such Google searches.
Then take a look at Codeigniter, http://codeigniter.com/user_guide/ it's organized, explains the how and why of MVC, is very very well documented and has a lot of great libraries for getting started, then once you get familiar with how everything works you can begin to look under the hood and start figuring out why it works the way it does and continue learning from there.
Then take a look at Codeigniter, http://codeigniter.com/user_guide/ it's organized, explains the how and why of MVC, is very very well documented and has a lot of great libraries for getting started, then once you get familiar with how everything works you can begin to look under the hood and start figuring out why it works the way it does and continue learning from there.
Actually, if you really want to learn PHP then CodeIgniter isn't the best place to start IMO. It's great to use as a tool for production. It's probably okay to get going at the very beginning. But if you want to really learn PHP, especially the new additions for PHP 5.3 then I suggest looking the code and using a PHP 5.3 framework. Look for a really small one so that you can see everything in the framework without having to look through a ton of files. Fatfree is one good example. A CodeIgniter based PHP 5.3 framework is fuelphp.
I won't tell you to abandon php (I haven't entirely either for pragmatic reasons) but I would suggest "going to the source" and learning about smalltalk. Other than the meta object stuff it will, in the main, transfer over to how you write php and think about OO. More pragmatically I'd also recommend learning from and leveraging the SPL stuff (http://www.php.net/~helly/php/ext/spl/)
The http://php.net/oop page is a great start. It lists all "modern features" of PHP. Almost all of which are used to write "great code".
take a look at the Zend Framework and site.
Some amazing docs and code there.
http://framework.zend.com/
Please help me to learn and grow. Oh, and don't tell me the best way to learn and grow because, well, because. You want advice but you already don't like the answer?
How/where can I learn this?
(Please don't say that I should pick another language. I'm fine with using PHP.)