DEV Community

loading...

Discussion on: Better strings in PHP

Collapse
aleksikauppila profile image
Aleksi Kauppila

Very nice, good job. I like the idea of implementing ArrayAccess here. Using global functions in PHP is a pain in the ass an not OOP at all. It's good to hide all of them into these sort of types.

Collapse
matthewbdaly profile image
Matthew Daly Author • Edited

Another thing I didn't mention in the post is that if you use value objects, you can use something like this as the base class for those, thereby getting all of that functionality easily. For instance, you could extend the custom string class into an Email class that validates the passed string is a valid email address when it's passed to the constructor, and typehint it to ensure that any method that receives an email gets an instance of Email and not just a generic string and it already has the various methods of the string class.

Forem Open with the Forem app