Closed HallofFamer closed 9 years ago
PHP, at least currently, does not distinguish between numeric and associative arrays - we could only determine this based on a full array scan (which is of course slow). In any case I'm also not really convinced it makes sense to provide two different APIs for them - this would only work well if we separate them in other parts of the language as well (in particular we'd need two typehints for example).
I see, I understand. So will you consider proposing this to PHP RFC if the scalar type hinting RFC get passed? I think scalar object will work very well with scalar type hinting.
I've answered in #20.
Well I've been playing with this on my own WAMP server and it's fabulous, oh my goodness how I wish this makes it to PHP 7 core. But lets take a step back, I think theres still some suggestions we can make this even better before moving forward. One idea I have is that array can be handled as numeric array and associative array. My idea is that for numeric array, it will still use the standard array handler as 'array', while for associative array it will be assigned to 'assoc'. This way we can distinguish between numeric and associative array, which is way better in my eyes. So here are my example:
register_primitive_type_handler('array', 'NumericArrayHandler'); // assigns handler to numeric array register_primitive_type_handler('assoc', 'AssociativeArrayHandler'); // assigns handler to assoc array
What is your take on this? Please let me know.