
Ask HN: What resources did you use to learn PHP? - woodsier
To complement the recent post regarding Python resources, I figure this is a great time to ask what resources (books, websites, tutorials, etc) people used to learn PHP.<p>I really want to learn PHP and MySQL properly this Christmas, and while I've completed the basic tutorials you'll find at the major websites, I want something that covers everything in-depth and facilitates the learning experience with good quality, <i></i>relevant<i></i> examples that you can see yourself actually using.<p>So I guess this question is really two-fold:<p>1) What resources did you use to learn?
2) Did you like them? And if you could do it again what resources would you use and in what order?
======
smoody
As with all languages, I think it requires being goal driven -- have something
you want to build -- and look up answers as required.

If you have the time, I recommend building a framework complete with a simple
ORM. Nothing will give you a quicker broad overview of any language's
strengths and weaknesses.

Also, most of the 'learning' about PHP is wrapping your head around the
included gigantic library of function calls and methods. There are a lot of
people who don't. When I was first learning, I'd search for ways to get
specific things done and almost always come across code where people manually
implemented things and I'd find out later that there's a function call that
does the job. Sometimes thats due to people not knowing about the fucntion and
sometimes that due to the post being outdated, so always look for the dates on
which advice is given. There are PHP5 ways to do things and pre-PHP5 ways to
do things.

Because of that, spend a few _days_ browsing the included library. And, make
sure you browse the comments people have left in the online documentation.
They are generally good quality, contain code samples, etc. If someone posts
bad code, others are quick to point out the flaws.

In the case of PHP, there is a lot of bad advice out there in general, so
choose wisely.

And, there are a few things that are hard to search for because they require
searching for single characters and search engines generally suck at it. Some
examples:

@ as in @function(x,y) - used for error suppression. & as in &$foo - pass by
reference instead of by value (automatic with objects but not arrays) $ as in
$foo(x,y,z) - dynamic function calling. the value of the string is the name of
the function that will be called. $ as in $foo->$bar - same thing with object
methods. $$ as in $$foo() - double dereference function calling. yuk.

Finally, I'd also browse around <http://www.stackoverflow.com> and look at the
php-tagged questions and answers.

~~~
thwarted
The PHP website is one of the most complete and easily navigable and
searchable language documentation websites I've ever used, and I directly
blame it for my being so well versed in PHP that PHP has (grudgingly) been my
tool of choice for years.

The quality of the documentation on php.net has actually gone down since they
started wrapping everything in objects and using automatic documentation
generators like doxygen. That's great for reference, but not so great when
you're trying to learn it. The documentation for SPL (largely
<http://www.php.net/~helly/php/ext/spl/> ) is an example. The php.net website
has traditionally been good for both reference and learning.

On the other hand, a lot of that "bad advice out there" is actually in the PHP
documentation (like building query strings directly), which has caused it to
pop up in other places. The comments on the documentation nodes are a great
idea, but use anything in them with caution. If one comment says "Here's how I
solved this problem..." there might already be function that did that and the
poster didn't know about it.

As for pass by reference working with objects but not arrays... I think a lot
of confusion over this comes from PHP4's crappy object model when objects were
passed by value (which doesn't make any sense in an object model) and that
people like to think of arrays like C arrays (which are just pointers). That
arrays are not passed by reference by default seems to fit the immutability of
other base types (however, I use the word "immutability" with caution there,
since it's not strict immutability in PHP).

------
coolboy89
First of all: Programming is learned by practicing, get off HN, books and just
do it.

If you are a person who can master a practical subject (typing code) by just
reading specifications, I'd recommend stop using PHP and maybe switch to a
more thoretical language; LISP, prolog, mathematica why not?

If you are a "mechanic" type of person why learn by experience, just start
programming, don't worry, you'll learn!

I recently programmed a site in PHP more or less boilerplaty. The idea to
avoid ugly, boring code is to abstract things away, supposedly by a framework
or by yourself. Nevertheless if you don't know what you're looking for, you
won't find it.

A thing i would probably use next time is MYSQL-classes as described in
[http://www.justincarmony.com/blog/2008/10/25/php-design-
bigg...](http://www.justincarmony.com/blog/2008/10/25/php-design-biggest-
database-oversights/).

A thing i would probably use next time is MORE regular expressions for
sanitizing input. Learn regexp, it's a time saver!

1) I too started with basic tutorials, but bit by bit startede gravitating
towards PHP.NET, finally landing in some nice PHP-framework. I see PHP as a
great language, but not a great framework. There are no prepackaged 'concepts'
of programming as in, for instance, ruby on rails. There is however lots of
nice low-level type of oppurtunities for clever hacks if you know the
technical bits, as in C.

2) I wouldn't think about it, as for always, i would start typing away. It's
not LISP, Prolog or Haskell where a lot of planning is involved.

------
adityakothadiya
When I started learning PHP, after basic tutorials of PHP, I jumped on MVC
framework called Symfony (<http://symfony-project.org/>). It's a great
framework and the documentation is really extensive with some basic examples
as well. You might wonder isn't starting with MVC was more extensive, but here
are the adavantages I found - 1\. MVC helped me to automate many things, so it
was faster productivity 2\. It showed me how to organize and structure the
code 3\. Though initially it kept details unknown from me, it was good because
it didn't baffle me a lot initially.

Once I started get going with my actual application, I started reading more
details of PHP as on when required. But MVC helped to accelerate my process of
building the real thing instead of investing of time in reading tutorials.

Also, I found these tutorials are good for plain PHP -
<http://www.phpro.org/tutorials/> . It also explains the MVC and all. So you
might want to read these tutorials, and then start with Symfony.

I hope this helps.

------
woodsier
I'm also interested in what your views are with learning inside a framework
such as CakePHP?

I ask this because I can see the upsides (learning in an environment which
fosters really good habits and quality code, however I can also see the
downside insofar that you are for the most part 1-step-removed from a lot of
the core functionality which is important to know.

~~~
thorax
I'm a big fan of Code Igniter-- I actually think you'll produce much better
PHP code if you learn a framework. It's really easy to design poorly with PHP
and a good framework can help build up good habits to take with you long-term.

CI is a light enough framework and you can diverge from it when needed to do
lower-level stuff. It also has a great user guide.

------
zandorg
At University. They gave us handout sheets. The coursework used SQL and PHP to
have an online register of school employees (eg, teachers).

------
Fuca
Just asked the same thing...Thanks everybody for the help

