1--TEST-- 2PDO Common: PDO::FETCH_CLASS 3--EXTENSIONS-- 4pdo 5--SKIPIF-- 6<?php 7$dir = getenv('REDIR_TEST_DIR'); 8if (false == $dir) die('skip no driver'); 9require_once $dir . 'pdo_test.inc'; 10PDOTest::skip(); 11?> 12--FILE-- 13<?php 14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); 15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 16$db = PDOTest::factory(); 17 18$db->exec('CREATE TABLE test005(id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10))'); 19$db->exec("INSERT INTO test005 VALUES(1, 'A', 'AA')"); 20$db->exec("INSERT INTO test005 VALUES(2, 'B', 'BB')"); 21$db->exec("INSERT INTO test005 VALUES(3, 'C', 'CC')"); 22 23$stmt = $db->prepare('SELECT id, val, val2 from test005'); 24 25class TestBase 26{ 27 public $id; 28 protected $val; 29 private $val2; 30} 31 32#[AllowDynamicProperties] // $val2 will be dynamic now. 33class TestDerived extends TestBase 34{ 35 protected $row; 36 37 public function __construct(&$row) 38 { 39 echo __METHOD__ . "($row,{$this->id})\n"; 40 $this->row = $row++; 41 } 42} 43 44$stmt->execute(); 45var_dump($stmt->fetchAll(PDO::FETCH_CLASS)); 46 47$stmt->execute(); 48var_dump($stmt->fetchAll(PDO::FETCH_CLASS, 'TestBase')); 49 50$stmt->execute(); 51var_dump($stmt->fetchAll(PDO::FETCH_CLASS, 'TestDerived', array(0))); 52 53?> 54--CLEAN-- 55<?php 56require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 57$db = PDOTest::factory(); 58PDOTest::dropTableIfExists($db, "test005"); 59?> 60--EXPECTF-- 61array(3) { 62 [0]=> 63 object(stdClass)#%d (3) { 64 ["id"]=> 65 string(1) "1" 66 ["val"]=> 67 string(1) "A" 68 ["val2"]=> 69 string(2) "AA" 70 } 71 [1]=> 72 object(stdClass)#%d (3) { 73 ["id"]=> 74 string(1) "2" 75 ["val"]=> 76 string(1) "B" 77 ["val2"]=> 78 string(2) "BB" 79 } 80 [2]=> 81 object(stdClass)#%d (3) { 82 ["id"]=> 83 string(1) "3" 84 ["val"]=> 85 string(1) "C" 86 ["val2"]=> 87 string(2) "CC" 88 } 89} 90array(3) { 91 [0]=> 92 object(TestBase)#%d (3) { 93 ["id"]=> 94 string(1) "1" 95 ["val":protected]=> 96 string(1) "A" 97 ["val2":"TestBase":private]=> 98 string(2) "AA" 99 } 100 [1]=> 101 object(TestBase)#%d (3) { 102 ["id"]=> 103 string(1) "2" 104 ["val":protected]=> 105 string(1) "B" 106 ["val2":"TestBase":private]=> 107 string(2) "BB" 108 } 109 [2]=> 110 object(TestBase)#%d (3) { 111 ["id"]=> 112 string(1) "3" 113 ["val":protected]=> 114 string(1) "C" 115 ["val2":"TestBase":private]=> 116 string(2) "CC" 117 } 118} 119TestDerived::__construct(0,1) 120TestDerived::__construct(1,2) 121TestDerived::__construct(2,3) 122array(3) { 123 [0]=> 124 object(TestDerived)#%d (5) { 125 ["id"]=> 126 string(1) "1" 127 ["val":protected]=> 128 string(1) "A" 129 ["val2":"TestBase":private]=> 130 NULL 131 ["row":protected]=> 132 int(0) 133 ["val2"]=> 134 string(2) "AA" 135 } 136 [1]=> 137 object(TestDerived)#%d (5) { 138 ["id"]=> 139 string(1) "2" 140 ["val":protected]=> 141 string(1) "B" 142 ["val2":"TestBase":private]=> 143 NULL 144 ["row":protected]=> 145 int(1) 146 ["val2"]=> 147 string(2) "BB" 148 } 149 [2]=> 150 object(TestDerived)#%d (5) { 151 ["id"]=> 152 string(1) "3" 153 ["val":protected]=> 154 string(1) "C" 155 ["val2":"TestBase":private]=> 156 NULL 157 ["row":protected]=> 158 int(2) 159 ["val2"]=> 160 string(2) "CC" 161 } 162} 163