PHP code example of evo / debug

1. Go to this page and download the library: Download evo/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/ */

    

evo / debug example snippets

   
    //construct or get an instance of Debug
    public static function getInstance(string $alias=''): self;
    //check if a given alias is instantiated
    public static function isInstantiated(string $alias=''): bool
    //register the procedural function
    public static function regesterFunctions(): void;
    //check if HTML mode is on
    public function getHtmlOutput(): bool;
    //change output to HTML mode [default is false]
    public function setHtmlOutput(bool $htmlOutput): void;
    //get the depth limit
    public function getDepthLimit(): int;
    //set the depth limit (how deep to dig into nested arrays and objects)
    public function setDepthLimit(int $depthLimit);
    //get the flags that are set
    public function getFlags(): int;
    //set flags
    public function setFlags(int $flags): void;
    //check if a flag is set
    public function hasFlag(int $flag): bool;
    //Debug and output 
    public function dump(mixed $input=null, int $offset = 0);
    //Debug and output 
    public function dumpException(Throwable $exception, int $offset = 0);
    //Debug and return 
    public function export(mixed $input=null, $offset = 0): string;
    //Start debugging output buffer, output will be capture until flush or end is called
    public function start(int $offset=0): void;
    //End debugging output buffer, and return it
    public function flush(int $offset=0): void;
    //End debugging output buffer, and output it
    public function end(int $offset=0): string;
    //Kill PHP execution with a message and a 
    public function kill(mixed $input=null, $offset=0);
    //debug without the outer formatting, output it
    public function varDump(mixed $input);
    //debug without the outer formatting, return it
    public function varExport(mixed $input, int $level=0, array $objInstances=array()): string;
    //return the part of the backtrace where this function was called from
    public function trace(int $offset=0): array;
    //print a backtrace - formatted like a stacktrace
    public function backTrace(int $offset=0): void;
    //return a backTrace
    public function getTraceFirst(int $offset=0): arrat;
    //return the formatted trace of getTraceFirst.
    public function getTraceFirstAsString(int $offset=0): string;

================================= evo\debug\Debug::dump ==================================
Output from FILE[ {yourpath}\index.php ] on LINE[ 25 ]
------------------------------------------------------------------------------------------
object(DebugTestItem)#0 (10) {
        ["CONSTANT":constant] => string(8) "constant",
        ["PUB_STATIC":public private] => string(10) "pub_static",
        ["PRO_STATIC":protected private] => string(10) "pro_static",
        ["PRI_STATIC":private private] => string(10) "pri_static",
        ["pub":public] => string(3) "pub",
        ["pro":protected] => string(3) "pro",
        ["pri":private] => string(3) "pri",
        ["array":public] => array(3){
                [0] => int(0),
                ["one"] => int(1),
                ["array"] => array(3){
                        [0] => string(3) "two",
                        [1] => string(5) "three",
                        [2] => string(4) "four",
                },
        },
        ["object":protected] => object(stdClass)#0 (0) {},
        ["self":private] => object(DebugTestItem)#0 (0) {~CIRCULAR_REFRENCE~},
}
==========================================================================================

//equire_once 'vendor/autoload.php';
//regester the procedural functions for debug
Debug::regesterFunctions();
//example of modifing the depth limit for the instance used in the procedural functions
Debug::getInstance(Debug::ALIAS_FUNCTIONS)->setDepthLimit(4);

debug_dump("foo"); //we'll say this is line 8 of index.php

if (!function_exists('debug_dump')) {
    /**
     *
     * {@inheritDoc}
     * @see \evo\debug\Debug::dump()
     */
    function debug_dump($input, $offset=1)
    {
        Debug::getInstance(Debug::ALIAS_FUNCTIONS)->dump($input, $offset); //this is line 20 of functions.php
    }
}

public function dump($input, $offset = 0)
{
  ...
}