Re: [RFC] Pipe Operator
| From: | François Laupretre | Date: | Sun, 15 May 2016 00:42:42 +0000 |
| Subject: | Re: [RFC] Pipe Operator | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93335@lists.php.net to get a copy of this message | ||
Le 13/05/2016 à 20:16, Sara Golemon a écrit :
After a quick check of every functions available in the PHP distrib, only 55 functions should insert the lhs in a position different from 0 (first argument). From these 55 functions, 4 must not be used in a pipeline and, for the remaining 51, the lhs must be inserted as 2nd, 3rd, or 4th argument. The list and positions to use are available at : http://tekwire.net/joomla/projects/ideas/pipe-operator So, the logic would be : - if the function accepts 0 mandatory argument, it cannot be used in a pipeline, - if the function is in the table referenced above, use the position from the table, - else, insert the lhs as 1st arg. For internal functions, we can easily use some unused part of the 1st arginfo element to store the position. The default will remain 0, which doesn't require any change in current arginfo declarations. We'll just have to define a new ZEND_BEGIN_ARG_INFO_xxx macro with an explicit position. This macro will be used for the 55 functions requiring a specific non-default position. -1 will be used to mark a function as unusable in a pipeline. Once again, I think that argument ordering is a very important issue and, here, we have an unique occasion to solve it for a rather moderate price, since every functions have been audited. Another issue is caused by the sort functions returning the sorted array by reference. The problem is the same with or without '$$'. In practice, these functions cannot be used in a pipeline. So, either we change their behavior to be different when used in a pipeline, which is weird but allows an intuitive '|> sort() |>' notation, or we need to define a new set of functions returning sorted arrays. None of these is perfect but we'll have to propose a solution, as sorting is essential when driving an array through a pipeline. Regards Françoisfor a potential solution to such a long-time issue as argument ordering sadness, IMHO, it's worth the pain. I am currently doing it and I'll send you the list when it is ready.Awesome. Even if not used in this feature, it could potentially be useful elsewhere. I hope you put it in a public gist or similar for posterity.