One thing you come to take for granted when using languages like Java or C# is that you need to declare your variables before you can use them. PHP doesn’t require you to do this - you can just merrily assign to whatever you want with no questions asked. Even Visual Basic - that much derided and bemoaned programming language - allowed you to force the declaration of variables using “Option Explicit”. Unfortunately there doesn’t appear to be a Option Explicit for PHP.
Recently I’ve been working on a fairly large and complex project using PHP that makes a lot of use of web services, XML parsing and subsequent database caching, and this omission from the language has been driving me mad! It would seem that 90% of the “bugs” that have cropped up have been due to assigning to “$XMLRetrn” instead of “$XMLReturn” (for example)…
But there is some hope! You can enable the “E_ALL” error reporting functionality which will display a “NOTICE” message on your page whenever you are assiging to an undefined variable. You can set this in the ini files (almost typed “phile” there…) but I personally like to do it in the file by file basis for finer grained control, for example:
error_reporting(E_ALL);
Having added this line you’ll then see some (or maybe a lot!) of the notice messages telling you where you’ve tried to assign to an undefined variable, e.g.:
# notice: Undefined variable: XMLRetrn in ws-controller.php on line 224.
Using these notices wont stop the PHP from actually trying to execute, but at least you will see a great big ugly message on the page telling you that you’ve probably just made a mistake. It has saved me a huge amount of time and frustration - hopefully it will help you too!