echo or print_r statements into the code with the goal of viewing the value of application variables as the page executes. While this approach certainly has its occasional merits, there is a far more effective technique, one that I guarantee will help set you on the road of success. This approach involves using an open source debugging tool named XDebug, and in this article I'll help you get started using this powerful solution.%>pecl install xdebug
php.ini file, replacing /PATH/TO with the actual path leading to the newly installed xdebug.so file. If you're using PHP in non-threaded mode (running it in CGI mode, for instance), insert the following line. Also be sure to use this variation if you're running PHP 5.3.zend_extension = /PATH/TO/xdebug.so
zend_extension_ts = /PATH/TO/xdebug.so
php.ini changes, restart your Web server, and load your PHP Info page (using the phpinfo()) function, and you should see a new section titled "xdebug," which contains quite a bit of information about the extension's configuration. I've included the top-most part of what that section will look like in Figure 1.
Click here for larger image
Figure 1. Check Your PHP Info Page to Make Sure XDebug Is Properly Installed
var_dump() function. For instance, consider the following example:<?php
class Book
{
private $_title;
private $_authors;
private $_pages;
public function setAuthors($authors)
{
$this->_authors = $authors;
}
}
$book = new Book();
$authors = array("Jason", "Eddie", "Jon");
$book->setAuthors($authors);
var_dump($book);
?>object(Book)#1 (3) { ["_title":"Book":private]=> NULL ["_authors":"Book":private]=>
array(3) { [0]=> string(5) "Jason" [1]=> string(5) "Eddie" [2]=> string(3) "Jon" }
["_pages":"Book":private]=> NULL object(Book)[1]
private '_title' => null
private '_authors' =>
array
0 => string 'Jason' (length=5)
1 => string 'Eddie' (length=5)
2 => string 'Jon' (length=3)
private '_pages' => null