php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46292 PDO::setFetchMode() shouldn't requires the 2nd arg when using FETCH_CLASSTYPE
Submitted: 2008-10-14 15:57 UTC Modified: 2008-10-14 17:53 UTC
From: felipe@php.net Assigned: felipe
Status: Closed Package: PDO related
PHP Version: 5.3CVS-2008-10-14 (CVS) OS:
Private report: No CVE-ID:
 [2008-10-14 15:57 UTC] felipe@php.net
Description:
------------
See below.

Reproduce code:
---------------
<?php

$pdoDb = new PDO('mysql:dbname=test;unix_socket=/var/run/mysqld/mysqld.sock', 'HELLO', 'WORLD :)', array(PDO::ATTR_EMULATE_PREPARES => false));

class myclass implements Serializable {
	public function __construct() {
		printf("%s()\n", __METHOD__);
	}
	
	public function serialize() {
		printf("%s()\n", __METHOD__);
		return "any data from serialize()";
	}
	
	public function unserialize($dat) {
		printf("%s(%s)\n", __METHOD__, var_export($dat, true));
		return $dat;
	}
}

class myclass2 extends myclass { }

$stmt = $pdoDb->prepare("SELECT * FROM testz");
var_dump($stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_GROUP));
$stmt->execute();

var_dump($stmt->fetch());
var_dump($stmt->fetch());

var_dump($stmt->fetchAll());


Expected result:
----------------
bool(true)
myclass::__construct()
object(myclass)#3 (1) {
  ["bar"]=>
  string(1) "1"
}
myclass::__construct()
object(myclass2)#3 (1) {
  ["bar"]=>
  string(1) "1"
}
array(0) {
}
[felipe php5]$ sapi/cli/php ~/public_html/bug.php 
bool(true)
myclass::__construct()
object(myclass)#3 (1) {
  ["bar"]=>
  string(1) "1"
}
myclass::__construct()
object(myclass2)#3 (1) {
  ["bar"]=>
  string(1) "1"
}
myclass::__construct()
array(1) {
  [0]=>
  object(myclass)#3 (1) {
    ["bar"]=>
    NULL
  }
}


Actual result:
--------------
bool(false)
array(4) {
  ["name"]=>
  string(7) "myclass"
  [0]=>
  string(7) "myclass"
  ["bar"]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
array(4) {
  ["name"]=>
  string(8) "myclass2"
  [0]=>
  string(8) "myclass2"
  ["bar"]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
array(1) {
  [0]=>
  array(4) {
    ["name"]=>
    string(7) "myclass"
    [0]=>
    string(7) "myclass"
    ["bar"]=>
    NULL
    [1]=>
    NULL
  }
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-14 17:53 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2.7, 5.3 and HEAD.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 02:02:27 2014 UTC