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
__toString() in UuidInterface #111
Comments
It's typically best in OOP to pass around objects rather than scalar values, so using the object instead of the string is a good idea, and you can typehint against the
|
No promises right now, but I'll consider the implications of adding |
Hey @jmauerhan
Yeah, I pass objects around, but for serialization and representation in HTTP context I need to cast it to string. That's why all value objects that can be serialized to string tend to have a
But if I do that, I can't cast it to string because I can't make sure that
That's what I do currently, but |
This would potentially fix a problem I have with api-platform where it doesn't know what to do with UuidInterface return values. |
@ramsey any update on this? Would be nice to finally have this |
I'll add I plan to make a big push to finish up all the things I want to implement for version 4 over the next couple of months. I'd like to have it out by the end of June. |
I'm just looking into this as well, what is the right usage for Typehinting when you have a HEX instead if a dashed UUID ? |
When you cast the |
OK, the class itself doesn't check for a valid string, that could be done on the construct, etc so you can typehint Or is it too much overhead to do that ? Could be added simply and is all in your library then. |
@Yamakasi see Ramsey\Uuid\Exception\InvalidUuidStringException which gets thrown when you attempt to use Uuid::fromString() on an invalid Uuid |
Oh, I've heard on Twitter something about 4.0 :P
So, speaking about that, there's something that always bother me. I like to cast UUID objects to string for persistence and representation, but there's no
__toString()
method inUuidInterface
.Ok, I could typehint against
Uuid
class, but if I do that, PHPStorm complains that return type ofUuid::uuid4()
(UuidInterface
) is not compatible with the expected type (Uuid
).So, could you add
__toString()
method inUuidInterface
for next 4.0 version?The text was updated successfully, but these errors were encountered: