]> granicus.if.org Git - php/commitdiff
Fixed bug #50636 (MySQLi_Result sets values before calling constructor)
authorPierrick Charron <pierrick@php.net>
Sun, 3 Jan 2010 16:59:33 +0000 (16:59 +0000)
committerPierrick Charron <pierrick@php.net>
Sun, 3 Jan 2010 16:59:33 +0000 (16:59 +0000)
NEWS
ext/mysqli/mysqli.c
ext/mysqli/tests/bug50636.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index cd166dca366aa895303ec3ca39d4df19b3430a0c..9a15e47f069694a46cc8fcd48de46e4e43621ac6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP                                                                        NEWS
   (Ilia)
 - Added stream_resolve_include_path(). (Mikko)
 
+- Fixed bug #50636 (MySQLi_Result sets values before calling constructor).
+  (Pierrick)
 - Fixed bug #48190 (Content-type parameter "boundary" is not case-insensitive
   in HTTP uploads). (Ilia)
 - Fixed bug #47409 (extract() problem with array containing word "this").
index 80e3759640b87f470aeb80ba71774a31096dab00..f5b7b9648702a2951feeb81b5c941061b4074611 100644 (file)
@@ -1205,7 +1205,6 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
                zval *retval_ptr; 
 
                object_and_properties_init(return_value, ce, NULL);
-               zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
 
                if (ce->constructor) {
                        fci.size = sizeof(fci);
@@ -1261,6 +1260,8 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
                } else if (ctor_params) {
                        zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name);
                }
+
+               zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
        }
 }
 /* }}} */
diff --git a/ext/mysqli/tests/bug50636.phpt b/ext/mysqli/tests/bug50636.phpt
new file mode 100644 (file)
index 0000000..47f2772
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Bug #50636 (MySQLi_Result sets values before calling constructor)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+       include ("connect.inc");
+
+    class Book {
+        private $title = 0;
+
+        function __construct() {
+            $this->title = 'foobar';
+        }
+
+        function __set($name, $value) {
+            $this->{$name}   = $value;
+        }
+    }
+
+    $link = new mysqli($host, $user, $passwd);
+    var_dump($link->query('SELECT "PHP" AS title, "Rasmus" AS author')->fetch_object('Book'));
+    echo "done!";
+?>
+--EXPECTF--
+object(Book)#%d (2) {
+  ["title":"Book":private]=>
+  string(3) "PHP"
+  ["author"]=>
+  string(6) "Rasmus"
+}
+done!