Open the-liquid-metal opened 5 years ago
While I love the idea of user-defined primitive type handling, I second this. I think we really should develop some standard base classes that people can use so that all the common functionality can be standardized.
OTOH, maybe this would happen through one or more PSRs?
Class gives additional weight. Not all people agree with standard base classes. If not, this would have been done a long time ago. That's why primitive type handling which has class flavour is a brilliant idea. As a bonus, you get less keystrok when declaring variable. Rather than typed like this $mystr = new String("hello")
, you only need to type $mystr = "hello"
, as usual. This is what JS do. The different is: in JS the variable is a real instance of class, but in PHP it is still primitive type.
I was developing one in C myself(a package called Scalar Classes) before my old PC died and the data scientists failed to recover my lost files. I may be doing it again later this year, if I have enough free time.
Hello. I think it is valuable if scalar_objects ships with standard classes, especially for codebase across multi project. I guess there will be a conflict if a project uses several library, and each of them uses their own classes. @HallofFamer has mentioned it on his post.
Some important things that must be considered are:
If scalar_objects has standard classes, users just simply consume it, more often cocktailed it, and rarely entends it. I think by using traits is the safest way to avoid conflict, especially if the methods has prefix specific for each library.
note:
To anticipate a very fat class of handler, i think it would be wise if scalar_objects provides additional methods (other than wrapper of native function), especially method which have functional style. As we know, php lack of functional style function/method. There are some libraries aim to cover this limitation. Some of them are just a clone of js library. A better thinking: provides functional style method of all procedural counterpart (if possible). The point is: don't give a room for users to reason that they need to extend it and litter the class.