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.
I'm a professional PHP, Python and Javascript developer from the UK. I've worked with Django, Laravel, and React, among others. I also maintain a legacy Zend 1 application.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
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.