Req #69106 [Opn]: Sortable interface

From: Date: Mon, 23 Feb 2015 06:29:16 +0000
Subject: Req #69106 [Opn]: Sortable interface
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190900@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69106&edit=1

 ID:                 69106
 User updated by:    thomas at gielfeldt dot dk
 Reported by:        thomas at gielfeldt dot dk
 Summary:            Sortable interface
 Status:             Open
 Type:               Feature/Change Request
 Package:            SPL related
 Operating System:   OSX
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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?


Previous Comments:
------------------------------------------------------------------------
[2015-02-23 00:35:35] requinix@php.net

See also http://marc.info/?l=php-internals&m=142438209810867&w=2

------------------------------------------------------------------------
[2015-02-22 21:36:25] 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)
  }
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69106&edit=1


Thread (7 messages)

« previous php.bugs (#190900) next »