The PHP debugging tool kint has a strange syntax where certain symbols can be prefixed to functions to alter their behavior, as shown in this guide.
The relevant information:
Modifiers are a way to change Kint output without having to use a different function. Simply prefix your call to kint with a modifier to apply it:
! Expand all data in this dump automatically
+ Disable the depth limit in this dump
- Attempt to clear any buffered output before this dump
@ Return the output of this dump instead of echoing it
~ Use the text renderer for this dump
Example:
+Kint::dump($data); // Disabled depth limit
!d($data); // Expanded automatically
How does this work?
By looking at the source code it seems that the symbols are being parsed into an array called $modifiers
. But how can you do this with PHP? And what is the scope of this, could I do this with other unicode symbols as well, or are the five in question (+, -, ~, !, @) the only ones.
The '@' already has a use in PHP when prefixed, see: What is the use of the @ symbol in PHP?. How can this be overruled?
Edit: A follow-up question to the answers given is how exactly kint bends the (php) rules. For example why the ~
doesn't give a syntax error. Consider this example:
<?php
function d($args) {
echo $args[0];
}
d([1,2,3]); // prints 1
~d([1,2,3]); // syntax error, unsupported operand types
vs
<?php
require 'kint.php';
~d([1,2,3]); // prints the array with the text renderer with no issues
Edit 2: removed unsubstantiated claim that kint uses eval()