News for hackers. Stuff that matters.
Re:25 Years of PHP [video] by Crazyontap on Sunday September 08, 2019 @03:43PM (#20912907)
Sorry I haven't watched the video (don't have headphones) but I can understand why php changes the order or function params sometimes like array_filter wants the array first and callback second and array_map wants it in reverse.

But if you think about it array_filter expects an array first and function second because the callback is optional and it compares to false if left out. OTOH with array_map there is only one function callback and there can be N number of arrays so the function needs to be the first and the arrays second.

It makes perfect sense to me but for a lot of people it may look like inconsistencies.

Re:25 Years of PHP [video] by viraptor on Sunday September 08, 2019 @10:22PM (#20914720)
It's not an either/or. Those signatures are inconsistent and there's a reason they were made that way. It could be done another way. (detecting the type of parameters or having a different name for the callback version)
Re:25 Years of PHP [video] by kristopolous on Monday September 09, 2019 @01:02AM (#20915332)
Why not just let the type system figure it out in this instance?
Re:25 Years of PHP [video] by tpetry on Monday September 09, 2019 @03:59AM (#20916082)
Because php has no function overloading by type system.
Re:25 Years of PHP [video] by kristopolous on Monday September 09, 2019 @04:41AM (#20916272)
The type can trivially be checked inside the function. You don't need type system function overloading
Re:25 Years of PHP [video] by totony on Monday September 09, 2019 @04:25PM (#20922069)
but this has runtime cost, where inconsistent order doesn't
Re:25 Years of PHP [video] by kristopolous on Monday September 09, 2019 @05:06PM (#20922483)
Not necessarily. Unless someone is intentionally trying to be confusing, the parameter order will be consistent for a specific instantiation.

I mean that if it's array,function at line X this time, it will be next time - again, unless you are trying to intentionally break this rule through a coding acrobatics exercise.

Since it's now known (with relative confidence), it can be optimized.

If someone truly is doing wacky things then we are left exactly where we were beforehand, with a broken system. Most of the time, however, it'd be better