Le 14/05/2016 à 01:36, Simon Welsh a écrit :
I’m not fond of this approach. Take in_array as an example. I have,
in the same file, piped an array in as the second argument and
piped a string in as the first. To have the position of the piped
variable be implicit, you’ll need multiple versions of in_array.

Sure, you could try to use the type of the value being passed in,
but that ends up much more magic and then you run into the same
problem with strpos, or password_verify, or a variety of other
functions that take multiple of the same type of argument where
order matters.

Right. Some functions may have several potential arguments to substitute. In this case, I propose we choose a position to use when the function is used in a pipe and, then, create function aliases with different positions.

Example :

Imagine we decide that in_array() substitutes the $needle arg :

$string |> in_array($haystack)

Then, we create a function alias, named 'array_contains()', whose only difference with in_array() is that it substitutes the $haystack argument :

$haystack |> array_contains($needle)

This way, we can create 2 or 3 ways to call the same function with different arguments to substitute.

Regards

François


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to