

Ask HN: How to write great PHP code? - hella

I've been able to hack together a few websites with PHP. But I still have no idea how to write good MVC, object-oriented code.<p>How/where can I learn this?<p>(Please don't say that I should pick another language. I'm fine with using PHP.)
======
mopoke
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...](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/>)

------
tgriesser
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.

~~~
gexla
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.

------
shaunxcode
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/>)

------
lastkarrde
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".

------
daz_miller
take a look at the Zend Framework and site. Some amazing docs and code there.
<http://framework.zend.com/>

------
dwc
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?

