1. Go to this page and download the library: Download phpixie/debug library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpixie / debug example snippets
g = new \PHPixie\Debug();
try{
throw new \Exception("test");
}catch(\Exception $e) {
//Pretty print an exception
$debug->exceptionMessage($e);
}
echo "\n-------\n";
//Automatic exception printing
//Will also display any logged messages
//(more on that later)
$debug->registerHandlers();
class Test
{
public function a($string)
{
$array = array(1, 2);
$this->b($string, $array);
}
public function b($string, $array)
{
$object = (object) array('t' => 1);
$this->c($string, $array, $object);
}
public function c()
{
substr();
}
}
$test = new Test();
$test->a("pixie");
PHPixie\Debug;
$debug = new Debug();
Debug::dump("Array dump:");
Debug::dump(array(1));
Debug::dump("Short array dump:");
//Short dump prints minimum information
//Which is useful to check array size
//or the class name of an object
Debug::dump(array(1), true);
$object = (object) array('t' => 1);
Debug::dump("Object dump:");
Debug::dump($object);
Debug::dump("Short object dump:");
Debug::dump($object, true);
Debug::dump("Dump trace with parameters");
class Test
{
public function a($string)
{
$array = array(1, 2);
$this->b($string, $array);
}
public function b($string, $array)
{
$object = (object) array('t' => 1);
$this->c($string, $array, $object);
}
public function c()
{
Debug::trace();
}
}
$t = new Test();
$t->a("test");
use PHPixie\Debug;
$debug = new Debug();
Debug::log("test");
Debug::log(array(3));
class Test
{
public function a($string, $num)
{
Debug::logTrace();
}
}
$t = new Test();
$t->a("test", 5);
//Displaying logged items
$debug->dumpLog();
use PHPixie\Debug;
$debug = new Debug();
//By passing 'true' to registerHandlers()
//we are also enabling dumping logged items
//after the script finishes
$debug->registerHandlers(true);
Debug::log("test");
echo("Logged messages will be printed below");
git clone https://github.com/phpixie/debug
cd debug/examples
#If you don't have Composer yet
curl -sS https://getcomposer.org/installer | php
php composer.phar install
php exceptions.php
php logging.php
php log_handler.php
php dumping.php
Exception: test
5
6 try{
> throw new \Exception("test");
8
9 }catch(\Exception $e) {
#0 D:\debug\examples\exceptions.php:7
-------
ErrorException: substr() expects at least 2 parameters, 0 given
36 public function c()
37 {
>> substr();
39 }
40 }
#0 D:\debug\examples\exceptions.php:38
#1 D:\debug\examples\exceptions.php:38
substr()
#2 D:\debug\examples\exceptions.php:33
Test->c('pixie', array[2], stdClass)
#3 D:\debug\examples\exceptions.php:27
Test->b('pixie', array[2])
#4 D:\debug\examples\exceptions.php:43
Test->a('pixie')
Logged items: