nikic / scalar_objects

Extension that adds support for method calls on primitive types in PHP
MIT License
1.13k stars 44 forks source link

Multiple Handlers for the same scalar type? #32

Open HallofFamer opened 7 years ago

HallofFamer commented 7 years ago

Hello there. I know right now when you assign a new handler, it will simply override the old handler, but I was wondering that in future, is it is possible to allow multiple scalar type handlers, assuming there is no conflict in the methods defined in each handler? Or are there technical difficulties to achieve this in the native C code?

nikic commented 7 years ago

I don't think it makes sense to support this natively (it seems too fragile as a default behavior), but you should be able to implement this in userland easily. Just add a handler that implements __callStatic() and then dispatch to the appropriate sub-handler that has that method.

mikeschinkel commented 4 years ago

@nikic — The biggest problem with not having multiple handlers is when frameworks, libraries or CMSes define their own handler if they do not allow their handler to be overridden.

Maybe you could add the ability to support adding a callback that would be called every time register_primitive_type_handler() is called to allow the developer to capture the handler others have added and/or allow the ability to chain handlers?