-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Feature request: display string lengths in var dumper #15856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The double quotes already imply that it's a string, what about a more intuitive syntax?
|
@iltar Indeed, my proposed syntax was a bit too much - the core proposal is to display the string length in the output, not the fact that it's a string. |
fyi, length is displayed on hover in html mode, so you'd like it in cli output also? |
(btw, my preference would go for |
@nicolas-grekas I never noticed the title attribute in html - thanks, but yes, something similar would be highly appreciated in cli mode (my preference would be the same). As for html output, perhaps there can be an option to toggle display as |
The downside of post-fixing it, means you won't be able to easily see the length without checking the end. With long strings this might be a bit annoying. |
Putting (what I think is) a secondary information in front of the main information would just clutter readability. Personally, I never read the length. It's usually useless information to me. That's why the output is the way it is now. IMHO, the readability loss is higher than the gain. I'd really like to discuss the need to output the length before we implement it if you think it's worth. |
One case where you might need it, is comparing strings that can contain zero-width spaces for example. |
I'm sure there is a use case, but should we clutter all and every dump just in case someone is in this very rare situation? |
Another (simple) use case is when you're dealing wish hashes - if you see an invalid length you know you missed something in your code. A third use case is dealing with encrypted data in limited-length datastores, allowing you to estimate how long the current code implementation can be used for. I see your point about clutter - indeed, there's no need to force this upon all users, so it could be made as an optional setting which is disabled by default. |
See #17305 |
…sentation (nicolas-grekas) This PR was merged into the 3.1-dev branch. Discussion ---------- [VarDumper] Add flags to allow fine tuning dumps representation | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15856 | License | MIT | Doc PR | - The `DUMP_STRING_LENGTH` behavior has been requested in #15856, the `DUMP_LIGHT_ARRAY` behavior is what should have been done for the VarDumperTestTrait. Anticipated usage is opt-in, by adding `<env name="DUMP_LIGHT_ARRAY" value="1" />` in `phpunit.xml.dist`. Any more flags proposal anyone? Better names maybe? Commits ------- a35ceb0 [VarDumper] Add flags to allow fine tuning dumps representation
I'm closing this as fixed because the feature was implemented by Nicolas in #17305 via the |
Hey folks. I've just started using the var dumper and it seems to lack a rather useful feature: displaying string lengths.
How it currently works
If one of the variables passed to the dumper is a string, it will be dumped as
"string-contents"
Proposed change
Display the string length in a manner similar to how array lengths are displayed:
A working example can be found in Raveren's Kint project.
The text was updated successfully, but these errors were encountered: