php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69106 Sortable interface
Submitted: 2015-02-22 21:36 UTC Modified: 2020-11-17 12:59 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: thomas at gielfeldt dot dk Assigned:
Status: Suspended Package: SPL related
PHP Version: Irrelevant OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thomas at gielfeldt dot dk
New email:
PHP Version: OS:

 

 [2015-02-22 21:36 UTC] thomas at gielfeldt dot dk
Description:
------------
A new interface "Sortable" and implementation of it on ArrayObject and ArrayIterator.

I could only get 5.6.3 to compile on my setup, so I hope someone can "port" it to 5.6. I've also made some unit tests for the new feature.

I'm not sure if my implementation is "the best solution" (tm), but I hope that I've at least done some footwork.

Test script:
---------------
$o = new ArrayObject(array(3,2,1));

var_dump($o);
sort($o);
var_dump($o);


Expected result:
----------------
object(ArrayObject)#1 (1) {
  ["storage":"ArrayObject":private]=>
  array(3) {
    [0]=>
    int(3)
    [1]=>
    int(2)
    [2]=>
    int(1)
  }
}
object(ArrayObject)#1 (1) {
  ["storage":"ArrayObject":private]=>
  array(3) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(3)
  }
}

Actual result:
--------------
class ArrayObject#1 (1) {
  private $storage =>
  array(3) {
    [0] =>
    int(3)
    [1] =>
    int(2)
    [2] =>
    int(1)
  }
}

Warning: sort() expects parameter 1 to be array, object given in /Users/thomas/develop/php-src/mytest.php on line 6

Call Stack:
    0.0010     226384   1. {main}() /Users/thomas/develop/php-src/mytest.php:0
    0.0030     228384   2. sort() /Users/thomas/develop/php-src/mytest.php:6

class ArrayObject#1 (1) {
  private $storage =>
  array(3) {
    [0] =>
    int(3)
    [1] =>
    int(2)
    [2] =>
    int(1)
  }
}

Patches

sortable_interface (last revision 2015-02-22 21:36 UTC by thomas at gielfeldt dot dk)

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-23 06:29 UTC] thomas at gielfeldt dot dk
Thanks. These features combined could be quite powerful I think, if I've understood Comparable correctly.


Btw, should I create a PR on github instead of uploading a patch here?
 [2015-02-23 06:57 UTC] requinix@php.net
Go ahead and make the PR so that there's a place online people can see the diff and comment on it, but you should also bring it up on the internals list for discussion. Perhaps even replying to the Comparable thread, if you can, since they're complementary subjects.
http://php.net/mailing-lists.php
 [2015-02-23 15:13 UTC] thomas at gielfeldt dot dk
Thanks. I think I'll implement this against the master branch before creating a PR, though. And perhaps attempt to create and RFC.
 [2020-11-17 12:59 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2020-11-17 12:59 UTC] cmb@php.net
As has been pointed out in the pull request, this feature requires
an RFC.  If you, or anybody is still interested in a Sortable
interface, please start the RFC process[1].  For the time being,
I'm suspending this ticket.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 12:01:29 2024 UTC