1--TEST-- 2Bug #46292 (PDO::setFetchMode() shouldn't requires the 2nd arg when using FETCH_CLASSTYPE) 3--SKIPIF-- 4<?php 5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); 6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 7MySQLPDOTest::skip(); 8if (version_compare(PHP_VERSION, '5.1.0', '<')) 9 die("skip Needs 5.1.0 and Interface Serializable"); 10?> 11--FILE-- 12<?php 13 14 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 15 $pdoDb = MySQLPDOTest::factory(); 16 17 18 class myclass implements Serializable { 19 public function __construct() { 20 printf("%s()\n", __METHOD__); 21 } 22 23 public function serialize() { 24 printf("%s()\n", __METHOD__); 25 return "any data from serialize()"; 26 } 27 28 public function unserialize($dat) { 29 printf("%s(%s)\n", __METHOD__, var_export($dat, true)); 30 return $dat; 31 } 32 } 33 34 class myclass2 extends myclass { } 35 36 $pdoDb->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 37 $pdoDb->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 38 39 $pdoDb->query('DROP TABLE IF EXISTS testz'); 40 41 $pdoDb->query('CREATE TABLE testz (name VARCHAR(20) NOT NULL, value INT)'); 42 43 $pdoDb->query("INSERT INTO testz VALUES ('myclass', 1), ('myclass2', 2), ('myclass', NULL), ('myclass3', NULL)"); 44 45 $stmt = $pdoDb->prepare("SELECT * FROM testz"); 46 47 var_dump($stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_GROUP)); 48 $stmt->execute(); 49 50 var_dump($stmt->fetch()); 51 var_dump($stmt->fetch()); 52 var_dump($stmt->fetchAll()); 53?> 54--CLEAN-- 55<?php 56require dirname(__FILE__) . '/mysql_pdo_test.inc'; 57$db = MySQLPDOTest::factory(); 58$db->exec('DROP TABLE IF EXISTS testz'); 59?> 60--EXPECTF-- 61bool(true) 62myclass::__construct() 63object(myclass)#%d (1) { 64 [%u|b%"value"]=> 65 %unicode|string%(1) "1" 66} 67myclass::__construct() 68object(myclass2)#%d (1) { 69 [%u|b%"value"]=> 70 %unicode|string%(1) "2" 71} 72myclass::__construct() 73array(2) { 74 [0]=> 75 object(myclass)#%d (1) { 76 [%u|b%"value"]=> 77 NULL 78 } 79 [1]=> 80 object(stdClass)#%d (1) { 81 [%u|b%"value"]=> 82 NULL 83 } 84} 85