584Part IIIAdvanced Features and TechniquesTry to isolate the (Web design online)
584Part IIIAdvanced Features and TechniquesTry to isolate the problemIf you can narrow the problem down to a single library or function, you ve made significantprogress in locating the cause. Use special echo()and print_r()calls to output trace infor- mation frequently. This will allow you to see when troublesome changes are taking place andwhen variables stop holding the values you think they re holding. You can also use a visual debugger (like Zend Studio, discussed later in this chapter) to moni- tor programs and their members as they execute. Simplify, then build upIt sounds obvious, but if you re having trouble with a given function or feature, cut it out (eitherliterally or with comments) and make sure everything runs without it. Then replace dynamicdata with static data (replace a database query with simple variable assignment statements). Get it working right under simple conditions, and add complexity in stages, testing all the wayto see when errors appear. Check the obviousWe ve all heard the story about the call to tech support in which the customer complains thathe can t see his mouse pointer move, and after lots of diagnostics it turns out that the machineisn t plugged in. It s probably apocryphal, but in any case make sure your Web server is work- ing properly on its own, and that a basic Hello, World script renders properly. You can alsoadd phpinfo()to the end of a simple test script to get a lot of information about your PHPinterpreter s version and environment details. Speaking of version, make sure you re not trying to do something that requires register_ globals(the infamous setting in php.ini) to be on. That setting is set to noby default, as ofPHP4.2, and it s tripped up more than one programmer. Document your solutionIt s extraordinarily common: You struggle with an error condition for hours (or longer) andfinally reach a solution. At that point, don t immediately head out to celebrate. Take a minuteto document what happened and what the solution was. That way, you ll be ready when thesame problem pops up again and it will. After fixing, re-testIt s not unusual to fix a problem and in doing so break something else. That s why it s impor- tant to retest your system beyond the scope of the bug you were originally after. This alsopoints out why it s important to isolate bugs as much as possible it limits the scope of re-testing you have to do. A Menagerie of BugsA number of different kinds of bugs plague programmers. Some bugs are both simple innature and easily found (as is the case with syntax errors and spelling mistakes). Others aresignificantly more difficult to catch, which is why this chapter is here.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.