A PHP port of Python's IceCream.
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()$ composer require --dev ntzm/icecreamIf 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().
- You should not call
icmore than once per line, otherwise you will get incorrect output
// Don't do this
ic('foo'); ic('bar');- You should not alias the
icfunction
// Don't do this
use function IceCream\ic as debug;
debug();- You should not use the
icfunction dynamically
// Don't do this
$fn = 'IceCream\ic';
$fn();