Req #69106 [Opn]: Sortable interface

From: Date: Tue, 24 Feb 2015 20:10:24 +0000
Subject: Req #69106 [Opn]: Sortable interface
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190937@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
 Updated by:         requinix@php.net
 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:

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


Previous Comments:
------------------------------------------------------------------------
[2015-02-23 15:13:38] 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.

------------------------------------------------------------------------
[2015-02-23 06:57:50] 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 06:29:16] 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 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 (#190937) next »