Comments (10)
I'll add __toString()
to version 4, but I can't add it to the interface on version 3.x, since that might break a lot of implementations.
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.
from uuid.
No promises right now, but I'll consider the implications of adding __toString()
to the UuidInterface
to ensure that all UUIDs can be treated like a string.
from uuid.
Hey @jmauerhan
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.
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 __toString()
method.
you can typehint against the UuidInterface instead of Uuid, and you won't get that error message
But if I do that, I can't cast it to string because I can't make sure that __toString()
method is implemented.
UuidInterface already has toString which is what Uuid::__toString calls. Maybe that will help? :)
That's what I do currently, but (string) $id
just feels better :P so I'd like to have it possible in 4.0.
from uuid.
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 UuidInterface
instead of Uuid
, and you won't get that error message.
UuidInterface
already has toString
which is what Uuid::__toString
calls. Maybe that will help? :)
from uuid.
This would potentially fix a problem I have with api-platform where it doesn't know what to do with UuidInterface return values.
Would also possibly simplify integrations similar types of projects.
from uuid.
No promises right now, but I'll consider the implications of adding __toString() to the UuidInterface to ensure that all UUIDs can be treated like a string.
@ramsey any update on this? Would be nice to finally have this
from uuid.
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 ?
from uuid.
When you cast the Uuid
object to a string, it is presented in the dashed, hexadecimal format. For type-hinting, it is a string
.
from uuid.
OK, the class itself doesn't check for a valid string, that could be done on the construct, etc so you can typehint Uuid
.
Or is it too much overhead to do that ? Could be added simply and is all in your library then.
from uuid.
@Yamakasi see Ramsey\Uuid\Exception\InvalidUuidStringException which gets thrown when you attempt to use Uuid::fromString() on an invalid Uuid
from uuid.
Related Issues (20)
- Misused Psalm Assertion for isValid() method? HOT 8
- Is there a way to force Uuid serialize to string instead of bytes ? HOT 7
- Could not find branch v5.x-dev anymore HOT 5
- Bad tag for 4.7.2 ? HOT 2
- ramsey/collection dependency requires PHP 8.1. HOT 2
- Ramsey\Uuid\Nonstandard namespace conflicts with itself in standalone builds HOT 2
- Unserialize error with OrderedTimeCodec HOT 2
- Remove the deleted tag in packagist.org HOT 3
- Deprecated: Return type of Ramsey\Uuid\Uuid::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): HOT 5
- Bump Bump brick/math from ^0.10 to ^0.11 HOT 2
- Mariadb 10.7+ uuid v7 sort HOT 1
- Interface 'Ramsey\Uuid\Provider\TimeProviderInterface' not found HOT 1
- Uuid v7 collisions HOT 9
- Deprecated Implements of Serializable in UuidInterface HOT 1
- Use a PSR clock for internal time management?
- Update brick/math to support v0.12.0
- Inconsistent results between fromString and isValid methods. HOT 2
- Uuid v7 generated in wrong order HOT 3
- Why doesn't this library use `hrtime()` for monotonicity? HOT 1
- Where is uuid7 method ?? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uuid.