php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73128 Add a sort method to the SPL Datastructures
Submitted: 2016-09-20 13:22 UTC Modified: -
Votes:17
Avg. Score:4.9 ± 0.5
Reproduced:17 of 17 (100.0%)
Same Version:16 (94.1%)
Same OS:16 (94.1%)
From: carlosv775 at gmail dot com Assigned:
Status: Open Package: SPL related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: carlosv775 at gmail dot com
New email:
PHP Version: OS:

 

 [2016-09-20 13:22 UTC] carlosv775 at gmail dot com
Description:
------------
Some Datastructures like SplFixedArray and SplObjectStorage could have a sort method where we can pass an optional callback and it sorts the original object or even return a new one.

Test script:
---------------
<?php
$array = new SplFixedArray(10);
for ($i = 0; $i < 10; $i++) {
    $array[$i] = mt_rand(1, 10);
};

$array->sort();
$array->sort(function ($a, $b) { return $b - $a; });
/**
 * Or:
 * $newArray = $array->sort();
 */

Expected result:
----------------
A sorted SPL Datastructure

Actual result:
--------------
FATAL ERROR Uncaught Error: Call to undefined method SplFixedArray::sort()

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC