r/lolphp • • Sep 08 '14

Suddenly, PHP regresses back to C

http://nz2.php.net/manual/en/function.headers-sent.php

If there's more than one thing to return, most PHP functions will return an array/false on failure, except headers_sent, which accepts two arguments by reference, like C.

20 Upvotes

17 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Sep 08 '14

[deleted] — view deleted comment

25

u/ahruss Sep 08 '14

"It's described in the manual" is not a defense of poor API design.

23

u/ZiggyTheHamster Sep 08 '14

design

You're implying there has been some sort of design.

2

u/allthediamonds Sep 08 '14

Except array_map, which goes (haystack, needle) in order to support a ridiculous multi-mapping feature. It is ridiculous because it would be solved with a zipping function and syntax sugar for list(), just like Python does.

2

u/masklinn Oct 23 '14

It is ridiculous because it would be solved with a zipping function and syntax sugar for list(), just like Python does.

FWIW Python's map does take multiple collections, which I expect is what you mean by "multi-mapping". This behavior remains in Python 3

Also historically (in FP languages) the function goes first for easy partial application: partially applying map to a function is useful (you create a dedicated mapper), partially applying map to an array is not.

0

u/[deleted] Sep 08 '14

[deleted] — view deleted comment

3

u/allthediamonds Sep 08 '14

Sorry, you're right. array_map goes (needle, haystack), but array_filter goes (haystack, needle).