Skip to content

ntzm/icecream-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IceCream PHP

A PHP port of Python's IceCream.

Usage

use function IceCream\ic;

function foo($i) {
    return $i + 333;
}

ic(foo(123));
// Outputs:
// ic| foo(123): 456

ic(1 + 5);
// Outputs:
// ic| 1 + 5: 6

ic(foo(123), 1 + 5);
// Outputs:
// ic| foo(123): 456, 1 + 5: 6

function bar() {
    ic();
}
bar();
// Outputs:
// ic| example.php:18 in bar()

Installation

$ composer require --dev ntzm/icecream

Configuration

If you want to disable the output, you can call IceCream::disable(). If you want to re-enable the output, you can call IceCream::enable().

If you want to change the prefix of the output, you can call IceCream::setPrefix('myPrefix: ') (by default the prefix is ic| ).

If you want to change how the result is outputted, you can call IceCream::setOutputFunction(). For example, if you want to log your messages to a file:

IceCream::setOutputFunction(function (string $message): void {
    file_put_contents('log.txt', $message . PHP_EOL, FILE_APPEND);
});

You can reset to the default output function by calling IceCream::resetOutputFunction().

Caveats

  • You should not call ic more than once per line, otherwise you will get incorrect output
// Don't do this
ic('foo'); ic('bar');
  • You should not alias the ic function
// Don't do this
use function IceCream\ic as debug;
debug();
  • You should not use the ic function dynamically
// Don't do this
$fn = 'IceCream\ic';
$fn();

About

Sweet and creamy debugging

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages