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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:30 2024 UTC