Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[uid] Please add ::toString() method to Symfony/Uid #53333

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

Closed
sofigio opened this issue Dec 31, 2023 · 4 comments
Closed

[uid] Please add ::toString() method to Symfony/Uid #53333

sofigio opened this issue Dec 31, 2023 · 4 comments

Comments

@sofigio
Copy link

sofigio commented Dec 31, 2023

Description

Just like the Ramsey class, we just want to print that uid as a string.
Currently, we must use ::toRfc4122() which every time makes me wonder "what is rfc 4122? I have to google that" and I waste time because I'm not sure it's the proper method, or as an alternative:

  • ->__toString()
  • (string) cast

which are aesthetically unpleasing. It would be a quality of life improvement to have a simple ->toString() method."

Example

No response

@xabbuh

This comment was marked as outdated.

@yceruto
Copy link
Member

yceruto commented Dec 31, 2023

Completely agree with you that ->toString() is better than ->__toString(), but that would mean having two methods with the same code just for aesthetics, which feels like a burden from the maintenance point of view.


Another alternative, as long as you don't declare(strict_types=1), is that you can use the Uid instance as a string everywhere (directly).

@wouterj
Copy link
Member

wouterj commented Dec 31, 2023

There are multiple ways you can visualize the UIDs implemented by the component as string. E.g. the __toString() method does not return RFC 4122 for ULIDs if I'm correct.

If you care about it being a string, it's probably also better to be explicit about which string format you want. If you don't care about its string visualization, but you just pass it to another domain expecting a string ID, you can either rely on PHP's type casting or use explicit casting using (string) $uid.

@fancyweb
Copy link
Contributor

fancyweb commented Jan 2, 2024

I think having toString() returning the canonical format makes sense DXwise.
The situation is not 100% comparable but we already have the 2 methods in AbstractString πŸ€·β€β™‚οΈ

@fabpot fabpot closed this as completed Jan 6, 2024
fabpot added a commit that referenced this issue Jan 6, 2024
This PR was merged into the 7.1 branch.

Discussion
----------

[Uid] Add `AbstractUid::toString()`

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | #53333
| License       | MIT

Commits
-------

9c24e5f [Uid] Add `AbstractUid::toString()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants