Giter Site home page Giter Site logo

__toString() in UuidInterface about uuid HOT 10 CLOSED

ramsey avatar ramsey commented on May 7, 2024 10
__toString() in UuidInterface

from uuid.

Comments (10)

ramsey avatar ramsey commented on May 7, 2024 14

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.

ramsey avatar ramsey commented on May 7, 2024 7

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.

danizord avatar danizord commented on May 7, 2024 5

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.

jmauerhan avatar jmauerhan commented on May 7, 2024

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.

nicholasruunu avatar nicholasruunu commented on May 7, 2024

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.

sserbin avatar sserbin commented on May 7, 2024

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.

Yamakasi avatar Yamakasi commented on May 7, 2024

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.

ramsey avatar ramsey commented on May 7, 2024

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.

Yamakasi avatar Yamakasi commented on May 7, 2024

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.

uphlewis avatar uphlewis commented on May 7, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.