DDC-1592: uasort - user function modyfied array #1997

Closed
opened 2026-01-22 13:37:05 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 10, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user gremplus:

$model - Doctrine ORM model with many2one relation to type model

$iterator = $model->getIterator();

$iterator->uasort(function($mps1, $mps2) {

    $display_order1 = (int)$mps1->getType()->getDisplayOrder();
    $display_order2 = (int)$mps2->getType()->getDisplayOrder();

    if($display*order1 === $display*order2) {
        return 0;
    }
    return ($display*order1 < $display*order2) ? -1 : 1;
});

This code return exception:
'ErrorException' with message 'uasort() [function.uasort]: Array was modified by the user comparison function'
After investigation, it was found out that problem is when lazy loading has occured.
If collection is already initialized there is no problem.
Version 2.0 has not this issue.

Originally created by @doctrinebot on GitHub (Jan 10, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user gremplus: $model - Doctrine ORM model with many2one relation to type model $iterator = $model->getIterator(); ``` $iterator->uasort(function($mps1, $mps2) { $display_order1 = (int)$mps1->getType()->getDisplayOrder(); $display_order2 = (int)$mps2->getType()->getDisplayOrder(); if($display*order1 === $display*order2) { return 0; } return ($display*order1 < $display*order2) ? -1 : 1; }); ``` This code return exception: 'ErrorException' with message 'uasort() [function.uasort]: Array was modified by the user comparison function' After investigation, it was found out that problem is when lazy loading has occured. If collection is already initialized there is no problem. Version 2.0 has not this issue.
admin added the Bug label 2026-01-22 13:37:05 +01:00
admin closed this issue 2026-01-22 13:37:06 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 10, 2012):

Comment created by adambro:

It seems to be known bug that is caused by changing number of references (i.e. throwing exception):
https://bugs.php.net/bug.php?id=50688

@doctrinebot commented on GitHub (Jan 10, 2012): Comment created by adambro: It seems to be known bug that is caused by changing number of references (i.e. throwing exception): https://bugs.php.net/bug.php?id=50688
Author
Owner

@doctrinebot commented on GitHub (Jan 15, 2012):

Comment created by @beberlei:

This is a PHP bug, please voice up in the issue mentioned above.

For now you can do the following in your code:

$entityManager->initializeObject($collection);
// sort now
@doctrinebot commented on GitHub (Jan 15, 2012): Comment created by @beberlei: This is a PHP bug, please voice up in the issue mentioned above. For now you can do the following in your code: ``` $entityManager->initializeObject($collection); // sort now ```
Author
Owner

@doctrinebot commented on GitHub (Jan 15, 2012):

Issue was closed with resolution "Can't Fix"

@doctrinebot commented on GitHub (Jan 15, 2012): Issue was closed with resolution "Can't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1997