summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2009-11-15 16:20:37 +0000
committerFelipe Pena <felipe@php.net>2009-11-15 16:20:37 +0000
commitae35c47a4bccf9f9464a518348b81fb0effc5bf6 (patch)
tree9cd52bed29cefbba3c58d1d75bfa2542fb890559
parent0d71754a2e4495e7a9e85b9834aa835c0014a1c1 (diff)
downloadphp-git-ae35c47a4bccf9f9464a518348b81fb0effc5bf6.tar.gz
- Fixed bug #49521 (PDO fetchObject sets values before calling constructor)
(patch by Pierrick)
-rw-r--r--NEWS2
-rwxr-xr-xext/pdo/pdo_stmt.c47
-rw-r--r--ext/pdo/tests/pdo_005.phpt8
-rw-r--r--ext/pdo_sqlite/tests/bug49521.phpt39
4 files changed, 71 insertions, 25 deletions
diff --git a/NEWS b/NEWS
index 103417a17d..9cd0f78eca 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? Nov 2009, PHP 5.2.12RC2
- Fixed bug #50174 (Incorrectly matched docComment). (Felipe)
+- Fixed bug #49521 (PDO fetchObject sets values before calling constructor).
+ (Pierrick)
12 Nov 2009, PHP 5.2.12RC1
- Updated timezone database to version 2009.18 (2009r). (Derick)
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 6b0d8b8120..ad38c36fe4 100755
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -1102,6 +1102,32 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value,
}
}
+ switch (how) {
+ case PDO_FETCH_CLASS:
+ if (ce->constructor && !(flags & PDO_FETCH_PROPS_LATE)) {
+ stmt->fetch.cls.fci.object_pp = &return_value;
+ stmt->fetch.cls.fcc.object_pp = &return_value;
+ if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc TSRMLS_CC) == FAILURE) {
+ pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor" TSRMLS_CC);
+ return 0;
+ } else {
+ if (stmt->fetch.cls.retval_ptr) {
+ zval_ptr_dtor(&stmt->fetch.cls.retval_ptr);
+ }
+ }
+ }
+ if (flags & PDO_FETCH_CLASSTYPE) {
+ do_fetch_opt_finish(stmt, 0 TSRMLS_CC);
+ stmt->fetch.cls.ce = old_ce;
+ stmt->fetch.cls.ctor_args = old_ctor_args;
+ stmt->fetch.cls.fci.param_count = old_arg_count;
+ }
+ break;
+
+ default:
+ break;
+ }
+
for (idx = 0; i < stmt->column_count; i++, idx++) {
zval *val;
MAKE_STD_ZVAL(val);
@@ -1235,27 +1261,6 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value,
}
switch (how) {
- case PDO_FETCH_CLASS:
- if (ce->constructor && !(flags & PDO_FETCH_PROPS_LATE)) {
- stmt->fetch.cls.fci.object_pp = &return_value;
- stmt->fetch.cls.fcc.object_pp = &return_value;
- if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc TSRMLS_CC) == FAILURE) {
- pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor" TSRMLS_CC);
- return 0;
- } else {
- if (stmt->fetch.cls.retval_ptr) {
- zval_ptr_dtor(&stmt->fetch.cls.retval_ptr);
- }
- }
- }
- if (flags & PDO_FETCH_CLASSTYPE) {
- do_fetch_opt_finish(stmt, 0 TSRMLS_CC);
- stmt->fetch.cls.ce = old_ce;
- stmt->fetch.cls.ctor_args = old_ctor_args;
- stmt->fetch.cls.fci.param_count = old_arg_count;
- }
- break;
-
case PDO_FETCH_FUNC:
stmt->fetch.func.fci.param_count = idx;
stmt->fetch.func.fci.retval_ptr_ptr = &retval;
diff --git a/ext/pdo/tests/pdo_005.phpt b/ext/pdo/tests/pdo_005.phpt
index c0264d9f3b..d30fccdf96 100644
--- a/ext/pdo/tests/pdo_005.phpt
+++ b/ext/pdo/tests/pdo_005.phpt
@@ -34,7 +34,7 @@ class TestDerived extends TestBase
public function __construct(&$row)
{
- echo __METHOD__ . "($row,{$this->id})\n";
+ echo __METHOD__ . "($row)\n";
$this->row = $row++;
}
}
@@ -108,9 +108,9 @@ array(3) {
string(2) "CC"
}
}
-TestDerived::__construct(0,1)
-TestDerived::__construct(1,2)
-TestDerived::__construct(2,3)
+TestDerived::__construct(0)
+TestDerived::__construct(1)
+TestDerived::__construct(2)
array(3) {
[0]=>
object(TestDerived)#%d (5) {
diff --git a/ext/pdo_sqlite/tests/bug49521.phpt b/ext/pdo_sqlite/tests/bug49521.phpt
new file mode 100644
index 0000000000..26cd2b2171
--- /dev/null
+++ b/ext/pdo_sqlite/tests/bug49521.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Bug #49521 (PDO fetchObject sets values before calling constructor)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_sqlite')) die ("skip Need PDO_SQlite support");
+?>
+--FILE--
+<?php
+
+class Book {
+ public $title = 'test';
+ public $author;
+
+ public function __construct($x) {
+ $this->title = '';
+ echo __METHOD__,"\n";
+ }
+ public function __set($a, $b) {
+ echo __METHOD__,"\n";
+ var_dump($a);
+ }
+}
+
+$pdo = new PDO('sqlite::memory:');
+$pdo->exec('CREATE TABLE book(title,author)');
+$pdo->exec('INSERT INTO book VALUES ("PHP","Rasmus")');
+$statement = $pdo->prepare('SELECT * FROM book WHERE title="PHP"');
+$statement->execute();
+var_dump($statement->fetchObject('Book', array(1)));
+
+?>
+--EXPECTF--
+Book::__construct
+object(Book)#%d (2) {
+ [%u|b%"title"]=>
+ string(3) "PHP"
+ [%u|b%"author"]=>
+ string(6) "Rasmus"
+}