Closed cuongngoz closed 2 years ago
Depends which part you want.
If you want the keys to be renamed to variables that'd be inaccurate, if you want the keys to be renamed to match the variables assigned to them that's not possible. At best you'd need some beefy static analysis to pull that off (At worst it'd be completely impossible)
If you just want them dumped at the top level, you can just expand the array like d(...$vars)
I tried d(...$vars)
but getting this
Kint::dumpAll requires arrays of identical size and keys as arguments
Huh. That's weird, I have a test dump of that kind but it works fine, but your example doesn't... I'll have to look into this
@cuongngoz That was a doozy - can you give ef433ccdeb0099fa222fad22ce86769169e3c754 a spin?
@jnvsor Cool, it works now.
But shall we output the key name only instead of having $vars[...
at prefix? or shouldn't? as it is intended to indicate the variable of the key and prevent duplicated key names with multiple variables right?
For example like this
But shall we output the key name only [...] as it is intended to indicate the variable of the key and prevent duplicated key names with multiple variables right?
Well the main thing I was thinking of was the access path, rather than the name. If you dump ...$vars
the access path for one of those would be $vars['params'][1]
not params[1]
so that would be incorrect.
The name itself can be duplicated if needed, it doesn't matter. It's just there to help the user understand which item they're looking at. I think if you d($a, $b, ...$c)
it's more immediately apparent what you're looking at to see $a, $b, $c['x'], $c['y'], $c['z']
than $a, $b, x, y, z
Given that this changes the function signature for a number of public methods on Kint\Kint
I'm going to do a little bit more work (Redundant parameters) to ensure no BC breaks then push to master
In the end for BC purposes I'm going to have to drop the associated keys altogether and treat them like numeric array unpacking. I've pushed 9230c016c976ff446f0be5cf82272db278344f69 and 3357a9fd2057c130694262d1011f8d1816cfe39b to my fork.
The first will go on a new 4.x branch as 4.2.2, the second will be the start of a 5.x target, but it probably won't be released just for this feature so it'll likely end up with PHP 8.2 support being the biggest feature
Currently It outputs like this May I ask could we support to print like this? while no need to pass specific variables to dump func (like
return new HtmlResponse(\Kint::dump($action, $method, $params));
) because just wanna let it more dynamic as the$vars
can be contained many items and then can show the key items at the first level (don't be collapsed)