From 6db67fe4ffc29c7eacc58b6bcbe62aff3dace294 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Sat, 4 Dec 2004 09:01:34 +0000 Subject: [PATCH] MFH: fix for bug #28817 (properties don't work in extended class) fix for bug #30890 (testsuite) --- ext/mysqli/mysqli.c | 6 +----- ext/mysqli/mysqli_prop.c | 36 ++++++++++++++++++---------------- ext/mysqli/tests/001.phpt | 27 +++++++++---------------- ext/mysqli/tests/002.phpt | 4 +++- ext/mysqli/tests/003.phpt | 4 +++- ext/mysqli/tests/004.phpt | 4 +++- ext/mysqli/tests/005.phpt | 4 +++- ext/mysqli/tests/006.phpt | 4 +++- ext/mysqli/tests/007.phpt | 4 +++- ext/mysqli/tests/008.phpt | 4 +++- ext/mysqli/tests/009.phpt | 4 +++- ext/mysqli/tests/010.phpt | 4 +++- ext/mysqli/tests/011.phpt | 4 +++- ext/mysqli/tests/012.phpt | 4 +++- ext/mysqli/tests/013.phpt | 4 +++- ext/mysqli/tests/014.phpt | 6 ++++-- ext/mysqli/tests/015.phpt | 6 ++++-- ext/mysqli/tests/016.phpt | 4 +++- ext/mysqli/tests/017.phpt | 10 +++++++--- ext/mysqli/tests/018.phpt | 4 +++- ext/mysqli/tests/019.phpt | 4 +++- ext/mysqli/tests/020.phpt | 4 +++- ext/mysqli/tests/021.phpt | 4 +++- ext/mysqli/tests/022.phpt | 4 +++- ext/mysqli/tests/023.phpt | 4 +++- ext/mysqli/tests/024.phpt | 4 +++- ext/mysqli/tests/025.phpt | 4 +++- ext/mysqli/tests/026.phpt | 8 ++++---- ext/mysqli/tests/027.phpt | 8 ++++---- ext/mysqli/tests/028.phpt | 8 ++++---- ext/mysqli/tests/029.phpt | 8 ++++---- ext/mysqli/tests/030.phpt | 7 ++++--- ext/mysqli/tests/031.phpt | 7 ++++--- ext/mysqli/tests/032.phpt | 8 ++++---- ext/mysqli/tests/033.phpt | 8 ++++---- ext/mysqli/tests/034.phpt | 8 ++++---- ext/mysqli/tests/035.phpt | 8 ++++---- ext/mysqli/tests/036.phpt | 4 +++- ext/mysqli/tests/037.phpt | 4 +++- ext/mysqli/tests/038.phpt | 4 +++- ext/mysqli/tests/039.phpt | 4 +++- ext/mysqli/tests/040.phpt | 4 +++- ext/mysqli/tests/041.phpt | 4 +++- ext/mysqli/tests/042.phpt | 4 +++- ext/mysqli/tests/043.phpt | 4 +++- ext/mysqli/tests/044.phpt | 4 +++- ext/mysqli/tests/045.phpt | 6 ++++-- ext/mysqli/tests/046.phpt | 4 +++- ext/mysqli/tests/047.phpt | 4 +++- ext/mysqli/tests/048.phpt | 4 +++- ext/mysqli/tests/049.phpt | 14 ++++++------- ext/mysqli/tests/050.phpt | 4 +++- ext/mysqli/tests/051.phpt | 4 +++- ext/mysqli/tests/052.phpt | 4 +++- ext/mysqli/tests/053.phpt | 4 +++- ext/mysqli/tests/054.phpt | 4 +++- ext/mysqli/tests/055.phpt | 4 +++- ext/mysqli/tests/056.phpt | 4 +++- ext/mysqli/tests/057.phpt | 4 +++- ext/mysqli/tests/058.phpt | 4 +++- ext/mysqli/tests/059.phpt | 4 +++- ext/mysqli/tests/060.phpt | 4 +++- ext/mysqli/tests/061.phpt | 4 +++- ext/mysqli/tests/bug29311.phpt | 10 +++++++--- ext/mysqli/tests/bug30967.phpt | 4 +++- 65 files changed, 240 insertions(+), 143 deletions(-) diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 833d8a5d07..96a56ae9dc 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -179,11 +179,6 @@ zval *mysqli_read_property(zval *object, zval *member, int type TSRMLS_DC) ret = FAILURE; obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC); - if (!obj->valid) { - retval = EG(uninitialized_zval_ptr); - return(retval); - } - if (member->type != IS_STRING) { tmp_member = *member; zval_copy_ctor(&tmp_member); @@ -223,6 +218,7 @@ zval *mysqli_read_property(zval *object, zval *member, int type TSRMLS_DC) } else { std_hnd = zend_get_std_object_handlers(); retval = std_hnd->read_property(object, member, type TSRMLS_CC); + retval->refcount = 1; } if (member == &tmp_member) { diff --git a/ext/mysqli/mysqli_prop.c b/ext/mysqli/mysqli_prop.c index 6ad8875680..f883e72de6 100644 --- a/ext/mysqli/mysqli_prop.c +++ b/ext/mysqli/mysqli_prop.c @@ -29,6 +29,15 @@ #include "ext/standard/info.h" #include "php_mysqli.h" +#define CHECK_OBJECT() \ + if (!obj->valid) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Property access is not allowed yet. Call the default constructor of the object first"); \ + ZVAL_NULL(*retval); \ + return SUCCESS; \ + } \ + + + #define MYSQLI_GET_MYSQL() \ MYSQL *p = (MYSQL *)((MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->mysql; @@ -41,9 +50,10 @@ MYSQL_STMT *p = (MYSQL_STMT *)((MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)- #define MYSQLI_MAP_PROPERTY_FUNC_LONG( __func, __int_func, __get_type, __ret_type)\ int __func(mysqli_object *obj, zval **retval TSRMLS_DC) \ {\ + ALLOC_ZVAL(*retval); \ + CHECK_OBJECT(); \ __ret_type l;\ __get_type;\ - ALLOC_ZVAL(*retval);\ if (!p) {\ ZVAL_NULL(*retval);\ } else {\ @@ -63,8 +73,9 @@ int __func(mysqli_object *obj, zval **retval TSRMLS_DC) \ int __func(mysqli_object *obj, zval **retval TSRMLS_DC)\ {\ char *c;\ + ALLOC_ZVAL(*retval); \ + CHECK_OBJECT(); \ __get_type;\ - ALLOC_ZVAL(*retval);\ if (!p) {\ ZVAL_NULL(*retval);\ } else {\ @@ -96,19 +107,6 @@ int link_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC) } /* }}} */ -/* {{{ property link_test_read */ -int link_test_read(mysqli_object *obj, zval **retval TSRMLS_DC) -{ - long i; - ALLOC_ZVAL(*retval); - array_init(*retval); - - for (i=0; i < 10; i++) - add_index_long(*retval, i, i + 10); - return SUCCESS; -} -/*i }}} */ - /* {{{ property link_connect_errno_read */ int link_connect_errno_read(mysqli_object *obj, zval **retval TSRMLS_DC) { @@ -147,9 +145,11 @@ MYSQLI_MAP_PROPERTY_FUNC_LONG(link_warning_count_read, mysql_warning_count, MYSQ /* {{{ property result_type_read */ int result_type_read(mysqli_object *obj, zval **retval TSRMLS_DC) { + ALLOC_ZVAL(*retval); + CHECK_OBJECT(); + MYSQL_RES *p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr; - ALLOC_ZVAL(*retval); if (!p) { ZVAL_NULL(*retval); } else { @@ -162,6 +162,9 @@ int result_type_read(mysqli_object *obj, zval **retval TSRMLS_DC) /* {{{ property result_lengths_read */ int result_lengths_read(mysqli_object *obj, zval **retval TSRMLS_DC) { + ALLOC_ZVAL(*retval); + CHECK_OBJECT(); + MYSQL_RES *p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr; ALLOC_ZVAL(*retval); @@ -202,7 +205,6 @@ mysqli_property_entry mysqli_link_property_entries[] = { {"affected_rows", link_affected_rows_read, NULL}, {"client_info", link_client_info_read, NULL}, {"client_version", link_client_version_read, NULL}, - {"test", link_test_read, NULL}, {"connect_errno", link_connect_errno_read, NULL}, {"connect_error", link_connect_error_read, NULL}, {"errno", link_errno_read, NULL}, diff --git a/ext/mysqli/tests/001.phpt b/ext/mysqli/tests/001.phpt index 5e483aba8d..880325bb5a 100644 --- a/ext/mysqli/tests/001.phpt +++ b/ext/mysqli/tests/001.phpt @@ -1,49 +1,40 @@ --TEST-- mysqli connect +--SKIPIF-- + --FILE-- --EXPECT-- -string(7) "1111111" +string(5) "11111" diff --git a/ext/mysqli/tests/002.phpt b/ext/mysqli/tests/002.phpt index 7925f84fa8..fa4e60e185 100644 --- a/ext/mysqli/tests/002.phpt +++ b/ext/mysqli/tests/002.phpt @@ -1,11 +1,13 @@ --TEST-- mysqli bind_result 1 +--SKIPIF-- + --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- +--SKIPIF-- + --FILE-- +--SKIPIF-- + --FILE-- --FILE-- --FILE-- - string(14) "root@localhost" + int(1) [1]=> string(4) "test" [2]=> diff --git a/ext/mysqli/tests/018.phpt b/ext/mysqli/tests/018.phpt index a0a247611d..4ba199d866 100644 --- a/ext/mysqli/tests/018.phpt +++ b/ext/mysqli/tests/018.phpt @@ -1,11 +1,13 @@ --TEST-- mysqli fetch system variables +--SKIPIF-- + --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- close(); mysqli_close($link); ?> +--SKIPIF-- + --FILE-- --FILE-- --FILE-- --FILE-- select_db("test"); $mysql->query("DROP TABLE IF EXISTS test_fetch_null"); diff --git a/ext/mysqli/tests/049.phpt b/ext/mysqli/tests/049.phpt index 04e705de6e..13ea5594c3 100644 --- a/ext/mysqli/tests/049.phpt +++ b/ext/mysqli/tests/049.phpt @@ -1,23 +1,23 @@ --TEST-- mysql_fetch_row (OO-Style) +--SKIPIF-- + --FILE-- select_db("test"); $result = $mysql->query("SELECT CURRENT_USER()"); $row = $result->fetch_row(); $result->close(); - - var_dump($row); + + $ok = ($row[0] == $user . "@" . $host); + var_dump($ok); $mysql->close(); ?> --EXPECT-- -array(1) { - [0]=> - string(14) "root@localhost" -} +bool(true) diff --git a/ext/mysqli/tests/050.phpt b/ext/mysqli/tests/050.phpt index 9ab5d346f8..5f923ccf34 100644 --- a/ext/mysqli/tests/050.phpt +++ b/ext/mysqli/tests/050.phpt @@ -1,5 +1,7 @@ --TEST-- non freed statement test +--SKIPIF-- + --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- connect("localhost", $user, $passwd); + $foo->connect($host, $user, $passwd); $foo->close(); printf("%s\n", $foo->test()); ?> diff --git a/ext/mysqli/tests/057.phpt b/ext/mysqli/tests/057.phpt index 581201d8ef..a987c72381 100644 --- a/ext/mysqli/tests/057.phpt +++ b/ext/mysqli/tests/057.phpt @@ -1,11 +1,13 @@ --TEST-- mysqli_get_metadata +--SKIPIF-- + --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- connect("localhost", "root", "", "test"); + global $host, $user, $passwd; + $this->connect($host, $user, $passwd, "test"); } } @@ -26,7 +30,7 @@ constructor test $foo[0] = new mysql1(); $foo[1] = new mysql2(); - $foo[2] = new mysql3("localhost", "root", "", "test"); + $foo[2] = new mysql3($host, $user, $passwd, "test"); for ($i=0; $i < 3; $i++) { diff --git a/ext/mysqli/tests/bug30967.phpt b/ext/mysqli/tests/bug30967.phpt index f441cf0f19..67c1fc22d1 100644 --- a/ext/mysqli/tests/bug30967.phpt +++ b/ext/mysqli/tests/bug30967.phpt @@ -1,5 +1,7 @@ --TEST-- Bug #30967 testcase (properties) +--SKIPIF-- + --FILE-- query("THIS DOES NOT WORK"); printf("%d\n", $mysql->errno); -- 2.40.0