Re: https://github.com/nikic/scalar_objects
Initial impression: This patch reminds me of extending native prototypes in Javascript,
with similar limitations that may explain why this has fallen out of fashion in JS. The
big one is that allowing change to the prototypes introduces global state with all the
problems that implies. The second is that you can't store local state beside the value.
E.g. a useful UTF-8 string class would want to store some extra state like: has the string
been validated, and are all chars in ASCII.
Other ideas:
-
Instead of registering a single class to wrap a native type, allow users to register
handlers that receive the native value, the type, the called method name, and args. This
allows altering behavior based on the value/method at call-time. The handler would return
a 2 member array: the first would indicate whether the handler actually handled the call,
the second would have the return value. -
Would it be possible to limit this behavior to a particular scope?