3 ms·
I tried to emulate something similar with PHP at one point. But the problem with PHP was parameter order. Especially in functions like array_key_exists() the ar
by habibur 1y ago
I tried to emulate something similar with PHP at one point. But the problem with PHP was parameter order. Especially in functions like array_key_exists() the array element is the 2nd parameter, while pipe operator expects the object to work on be the 1st parameter, the array in these cases.
I believe they have solved this problem by now. Though no idea how.
- kijin 1y agoThe usual solution is to wrap it with a closure. function($x) { return array_key_exists('needle', $x); } Or using the arrow function syntax: fn($x) => array_key_exists('needle', $x) The same trick also helps when you need to use functions with mandatory extra parameters, functions with pass-by-value parameters, etc.
- moebrowne 1y agoIf the Partial Function Application RFC passes then the closure wont be necessary https://wiki.php.net/rfc/partial_function_application_v2 https://wiki.php.net/rfc/partial_function_application_v2