<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>[PHP-DEV] [VOTE] array_part()</title>
        <description> I've opened the array_part() vote:

https://wiki.php.net/rfc/array_part#vote

The vote asks whether the branch at  
https://github.com/cataphract/php-src/tree/array_part should be merged.  
This implementation has been tested and has 100% code coverage on the  
reachable code.

-- 
Gustavo Lopes

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php</description>
        <link>http://www.serverphorums.com/read.php?7,504218,504218#msg-504218</link>
        <lastBuildDate>Sat, 18 May 2013 17:56:44 +0200</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://www.serverphorums.com/read.php?7,504218,504487#msg-504487</guid>
            <title>Re: [PHP-DEV] [VOTE] array_part()</title>
            <link>http://www.serverphorums.com/read.php?7,504218,504487#msg-504487</link>
            <description><![CDATA[ On Tue, 29 May 2012 02:28:05 +0200, Stas Malyshev &lt;smalyshev@sugarcrm.com&gt;  <br />
wrote:<br />
<br />
&gt; This looks very complicated. It might be that some use cases require<br />
&gt; this level of complexity, but I can't remember a case where I would need<br />
&gt; it. That alone does not disqualify the proposal, but I personally very<br />
&gt; much like having something like array_column() rather than whole array<br />
&gt; slicing engine with it's own declarative language inside. The engine<br />
&gt; might be fine, but I imagine many users would want just something like<br />
&gt; array_column() - so at least it'd be nice to have both.<br />
<br />
1)<br />
Independently for whether we want array_column this function does things  <br />
that no other function built-in currently does and some that no userland  <br />
function can even do:<br />
<br />
* Extract slices without side effects (array_slice() has side effects).<br />
* Extract slices based on keys on time proportional to the size of the  <br />
slice and not to the size of the array.<br />
* Pick an arbitrary number of elements from an array in any permutation  <br />
and traversing the array, in worst case -- if we request an element in the  <br />
middle --, only once.<br />
<br />
2)<br />
A lot of people seem to think this is too complicated. I think that  <br />
objection comes from several places:<br />
<br />
* People focusing on the most complex usages of the function. The test  <br />
cases have to cover complex usages in order to exercise the implementation  <br />
correctly, but that doesn't mean the majority of use cases will be that  <br />
complex.<br />
* The syntax for contiguous slices is verbose (e.g. ['start'=&gt;1, 'end'=&gt;3]  <br />
instead of [1:3] or [1..3] like in other languages).<br />
* Specifying we want all the elements in a level could be simpler (e.g.  <br />
using null instead of ['start'=&gt;0] or ['start'=&gt;null]). See above.<br />
* The description of the function aims to be precise and is therefore  <br />
verbose. This was probably a strategic miscalculation on my part.<br />
<br />
Let me exemplify how this function may make things simpler. Right now,  <br />
let's suppose you want to drop the first element on each level. Let's say  <br />
you have this array:<br />
<br />
$arr =<br />
[<br />
   ['col1',  'col2', 'col3'],<br />
   ['line1', 0,      1     ],<br />
   ['line2', 1,      0     ],<br />
]<br />
<br />
To drop the headers, you'd now have to do:<br />
<br />
array_slice(array_map(function($a) { return array_slice($a,1); }, $arr),  <br />
1);<br />
<br />
With array_part, you can do:<br />
<br />
array_part($arr, [ ['start'=&gt;1], ['start'=&gt;1] ]);<br />
<br />
or in this case:<br />
<br />
array_part($arr, [ [1, 2], [1, 2] ]);<br />
-- <br />
Gustavo Lopes<br />
<br />
-- <br />
PHP Internals - PHP Runtime Development Mailing List<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Gustavo Lopes</dc:creator>
            <category>php-internals</category>
            <pubDate>Tue, 29 May 2012 10:10:01 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?7,504218,504374#msg-504374</guid>
            <title>Re: [PHP-DEV] [VOTE] array_part()</title>
            <link>http://www.serverphorums.com/read.php?7,504218,504374#msg-504374</link>
            <description><![CDATA[ Hi!<br />
<br />
&gt; I've opened the array_part() vote:<br />
&gt; <br />
&gt; <a href="https://wiki.php.net/rfc/array_part#vote" target="_blank"  rel="nofollow">https://wiki.php.net/rfc/array_part#vote</a><br />
&gt; <br />
&gt; The vote asks whether the branch at  <br />
&gt; <a href="https://github.com/cataphract/php-src/tree/array_part" target="_blank"  rel="nofollow">https://github.com/cataphract/php-src/tree/array_part</a> should be merged.  <br />
&gt; This implementation has been tested and has 100% code coverage on the  <br />
&gt; reachable code.<br />
<br />
This looks very complicated. It might be that some use cases require<br />
this level of complexity, but I can't remember a case where I would need<br />
it. That alone does not disqualify the proposal, but I personally very<br />
much like having something like array_column() rather than whole array<br />
slicing engine with it's own declarative language inside. The engine<br />
might be fine, but I imagine many users would want just something like<br />
array_column() - so at least it'd be nice to have both.<br />
-- <br />
Stanislav Malyshev, Software Architect<br />
SugarCRM: <a href="http://www.sugarcrm.com/" target="_blank"  rel="nofollow">http://www.sugarcrm.com/</a><br />
(408)454-6900 ext. 227<br />
<br />
-- <br />
PHP Internals - PHP Runtime Development Mailing List<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Stas Malyshev</dc:creator>
            <category>php-internals</category>
            <pubDate>Tue, 29 May 2012 02:30:04 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?7,504218,504218#msg-504218</guid>
            <title>[PHP-DEV] [VOTE] array_part()</title>
            <link>http://www.serverphorums.com/read.php?7,504218,504218#msg-504218</link>
            <description><![CDATA[ I've opened the array_part() vote:<br />
<br />
<a href="https://wiki.php.net/rfc/array_part#vote" target="_blank"  rel="nofollow">https://wiki.php.net/rfc/array_part#vote</a><br />
<br />
The vote asks whether the branch at  <br />
<a href="https://github.com/cataphract/php-src/tree/array_part" target="_blank"  rel="nofollow">https://github.com/cataphract/php-src/tree/array_part</a> should be merged.  <br />
This implementation has been tested and has 100% code coverage on the  <br />
reachable code.<br />
<br />
-- <br />
Gustavo Lopes<br />
<br />
-- <br />
PHP Internals - PHP Runtime Development Mailing List<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Gustavo Lopes</dc:creator>
            <category>php-internals</category>
            <pubDate>Mon, 28 May 2012 15:40:02 +0200</pubDate>
        </item>
    </channel>
</rss>
