All pastes #589074 Raw Edit

Someone

public text v1 · immutable
#589074 ·published 2007-06-25 20:09 UTC
rendered paste body
Le problème est dans cette boucle.
Quand on itère sur un $quantity > 1, tous les objets ajoutés ont le même ID que le dernier inséré. Voir en bas le 'dump'.

            foreach ($add_float as $id => $quantity) {
              for ($n=0; $n < $quantity; $n++) {
                $new_from_float = $reverse_floating[$id];
                $tmp=$new_from_float->get_obj();
                $new_from_float->datas['ID'] = max($auths->get_max_elt_id(),max_elt($floating))+1;
                $sub_elt = $new_from_float->datas['ID'];
                
                if (($tmp['type'] == 'nufw') or ($tmp['type'] == 'link')){
                  $working_elt->add_elt($new_from_float);
#                  $used_desc=$_SESSION['used_desc'];
#                  check_objects_from_desc(&$ressources,$descs->elts[$used_desc]);
    #              print_r($working_elt);
                  $_SESSION['document']=serialize($expolicy);
#                 $auths=&$expolicy->auths;
                  print_r($working_elt);
                  $_SESSION['modified']=1;
#                  $_SESSION['need_acl_recalc']=1;
                }else{
                  add_log($auth_bad_type);
                }
              }
            } 

Les fonctions sont très simples :
function add_elt($elt){
    $this->elts[$elt->get_id()]=$elt;
}

function get_id(){
   return($this->ID);
}


Le dump :
À la première itération, $n = 0 :
auth Object
(
    [name] => mon_working_elt
    [operator] => 
    [ID] => 10
    [elts] => Array
        (
            [23] => elt Object
                (
                    [datas] => Array
                        (
                            [type] => link
                            [name] => _link
                            [ID] => 23
                        )

                )

        )

)
À la deuxième itération, $n = 1, l'ID du premier élément se trouve corrompu (!!)
auth Object
(
    [name] => mon_working_elt
    [operator] => 
    [ID] => 10
    [elts] => Array
        (
            [23] => elt Object
                (
                    [datas] => Array
                        (
                            [type] => link
                            [name] => _link
                            [ID] => 24
                        )

                )

            [24] => elt Object
                (
                    [datas] => Array
                        (
                            [type] => link
                            [name] => _link
                            [ID] => 24
                        )

                )

        )

)