I lost a lot of time on problems like this. I often did not get what I expected.
I don't know what sort of debugging feature you have.
As an editor I use phpide (phpcoder) from www.phpide.de. It should have a debug facility built in but I cannot get it to work; along with many others. However I like the program.
What I do now is stick lines in such as
echo "The value of myvar is ".$myvar."<br>";
all over the place so that I can see what the value of a particular variable is at different parts of the program. I get some nasty surprises. The variable is often not what I thought it should be and that's how I find out what is going wrong.
The examples in that book are also super. You learn lots by studying them, particularly as many of them are actual applications that work.
Cheers and good luck; fascinating language this PHP.
Paul