php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64864 shuffle() and array_push are broken with PDO.
Submitted: 2013-05-16 20:32 UTC Modified: 2013-05-16 22:56 UTC
From: mail at kinesis dot me Assigned:
Status: Closed Package: PDO related
PHP Version: 5.4.15 OS: Ubuntu Linux 13.04 x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mail at kinesis dot me
New email:
PHP Version: OS:

 

 [2013-05-16 20:32 UTC] mail at kinesis dot me
Description:
------------
$this->answer['id'] is always at the end, when it is supposed to be shuffled.

This looks like a bug to me. array_rand() will not work either. 

            $this->current_set=$this->dbh->query("SELECT DISTINCT id FROM $game_type WHERE id != '".(string)$this->answer['id']."' ORDER BY rand() LIMIT 2;")->fetchAll(PDO::FETCH_COLUMN);
            //$this->complete_set=""
            //echo "Current set separated by commas is ".implode(",",$this->current_set->fetchAll(PDO::FETCH_COLUMN)) + $this->answer['id']."<br />";
            //$this->current_set=$this->current_set->fetchAll(PDO::FETCH_COLUMN);

            array_push($this->current_set,$this->answer['id']);
            explode(",",$this->current_set);
            shuffle($this->current_set); // $this->answer['id'] is always at the end?
            print_r($this->current_set);
            print_r($this->answer['id']);
            var_dump($this->current_set, 3);

Test script:
---------------
            $this->current_set=$this->dbh->query("SELECT DISTINCT id FROM $game_type WHERE id != '".(string)$this->answer['id']."' ORDER BY rand() LIMIT 2;")->fetchAll(PDO::FETCH_COLUMN);
            //$this->complete_set=""
            //echo "Current set separated by commas is ".implode(",",$this->current_set->fetchAll(PDO::FETCH_COLUMN)) + $this->answer['id']."<br />";
            //$this->current_set=$this->current_set->fetchAll(PDO::FETCH_COLUMN);

            array_push($this->current_set,$this->answer['id']);
            explode(",",$this->current_set);
            shuffle($this->current_set); // $this->answer['id'] is always at the end?
            print_r($this->current_set);
            print_r($this->answer['id']);
            var_dump($this->current_set, 3);

Expected result:
----------------
I expect the array '$this->current_set' to have the value of $this->answer pushed towards the end. Then I shuffle() or array_rand() the array, but $this->answer always appears as the third element of the array no matter what I do.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-16 22:56 UTC] mail at kinesis dot me
-Status: Open +Status: Closed
 [2013-05-16 22:56 UTC] mail at kinesis dot me
I was seeding the random number generator with 0.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 22:03:38 2021 UTC