On Mon, Feb 8, 2016 at 11:38 AM, Rowan Collins <rowan.coll...@gmail.com> wrote:
> Kinn Julião wrote on 08/02/2016 16:05: > >> That's the nice thing about userland... you are giving them ability to >> implement what they want! >> `array_filter([...], 'is_int', ARRAY_FILTER_USE_KEY)` does the job as the >> others... don't think having a new function would prevent this. >> > > It does the job, but it is much less efficient in some cases than the > foreach and return false case, as it must examine every element; it also > has unnecessary memory overhead, creating a filtered list which exists only > to be counted and thrown away; and an internal implementation could be > optimised even further by exploiting the way the engine stores the array > internally. > How does `array_filter([...], 'is_int', ARRAY_FILTER_USE_KEY)` add that *much* overhead? And if that's the case, instead of introducing a 99999 array function into the core, why not just create a new Object then? $list = list('foo','bar'); // I know it's a reserved token, don't have time to find a better synonym. it's just a sample $list[2] = 'baz'; var_dump($list); string(1) "foo" string(1) "bar" string(1) "baz" $list['a'] = 'foobar'; // Fatal error. > > PHP is at this stage expressive enough that a large number of core > functions could be rewritten in multiple ways using other core functions, > but that doesn't automatically rule out adding more functions to core where > it is useful to do so. PHP is at a stage where we can add support to a better structure and objects support... we don't need a function to check if the keys are integer, we need an object that only supports integer as keys, or even a generic key... Would rather have `Map<int, mixed>` than `has_numeric_keys` > > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- *--* *Kinn Coelho Julião* *Toronto - ON/Canada*