PHP code example of darkfriend / php7-debug

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

    

darkfriend / php7-debug example snippets


// basic usage
\darkfriend\helpers\Trace::add('my message'); // добавляет строку
// \darkfriend\helpers\Trace::add(['my message']); // добавляем любой массив или объект

// example: set trace file
\darkfriend\helpers\Trace::init(
    null,
    null,
    './logs/trace.log'
);
\darkfriend\helpers\Trace::add('my message'); // добавляет строку в файл trace.log
// \darkfriend\helpers\Trace::add(['my message']); // добавляем любой массив или объект в файл trace.log

\darkfriend\helpers\Trace::init(
    null,
    null,
    './logs/custom.log'
);
\darkfriend\helpers\Trace::add('my message'); // добавляет строку в файл custom.log
// \darkfriend\helpers\Trace::add(['my message']); // добавляем любой массив или объект в файл custom.log

// basic usage
\darkfriend\helpers\Log::add('my message'); // добавляет строку
// \darkfriend\helpers\Trace::add(['my message']); // добавляем любой массив или объект

// example: set trace file
\darkfriend\helpers\Log::init(
    null,
    null,
    './logs/basic.log'
);
\darkfriend\helpers\Log::add('my message'); // добавляет строку в файл basic.log
// \darkfriend\helpers\Trace::add(['my message']); // добавляем любой массив или объект в файл basic.log

\darkfriend\helpers\Log::init(
    null,
    null,
    './logs/custom.log'
);
\darkfriend\helpers\Log::add('my message'); // добавляет строку в файл custom.log
// \darkfriend\helpers\Trace::add(['my message']); // добавляем любой массив или объект в файл custom.log

use \darkfriend\devhelpers\DebugHelper;
$data = [
  'key1' => 'value1',
  'key2' => 'value2',
  'key3' => [
    'subKey1' => 'subValue1',
    'subKey2' => 'subValue2',
  ],
];
DebugHelper::print_pre($data);

use \darkfriend\helpers\DebugHelper;
$data = [
  'key1' => 'value1',
  'key2' => 'value2',
  'key3' => [
    'subKey1' => 'subValue1',
    'subKey2' => 'subValue2',
  ],
];

// способ 1: используя $params
DebugHelper::call(function($data) {
  DebugHelper::print_pre($data);
},$data);

// способ 2: используя use
DebugHelper::call(function() use ($data) {
  DebugHelper::print_pre($data);
});

use \darkfriend\helpers\DebugHelper;
$array1 = [
  'key1' => 'value1',
  'key2' => 'value2'
];

// trace 1
DebugHelper::trace($array1);
// итог: запишет $array1 с категорией common.

$array1['key3'] = [
  'subKey1' => 'subValue1',
  'subKey2' => 'subValue2',
];

// trace 2
DebugHelper::trace($array1);
// итог: допишет в лог обновленный $array1 с категорией common

use \darkfriend\helpers\DebugHelper;

$id = 1; // идентификатор

// делаем инициализацию
// $id - ключ trace-session
// self::TRACE_MODE_SESSION - включаем режим trace-session
DebugHelper::traceInit($id, DebugHelper::TRACE_MODE_SESSION);

$array1 = [
  'key1' => 'value1',
  'key2' => 'value2',
  'key3' => 'value3'
];

DebugHelper::trace($array1);
// итог: запишет $array1 с категорией common.

$array1['key3'] = [
  'subKey1' => 'subValue1',
  'subKey2' => 'subValue2',
];

// trace 2
DebugHelper::trace($array1);
// итог: допишет в лог обновленный $array1 с категорией common