summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2021-03-17 09:39:54 +0100
committerMáté Kocsis <kocsismate@woohoolabs.com>2021-03-17 09:42:35 +0100
commitf15d52796ebe7e44fef67b733422b85d69581b08 (patch)
tree97b5f0a297013458be16db6d45c612375ba2ac12
parent1494e87bd0de24f83e8953baec86d25ed2f1d034 (diff)
downloadphp-git-f15d52796ebe7e44fef67b733422b85d69581b08.tar.gz
Declare PDORow::queryString property
Relates GH-6742
-rw-r--r--ext/pdo/pdo_stmt.c18
-rw-r--r--ext/pdo/pdo_stmt.stub.php4
-rw-r--r--ext/pdo/pdo_stmt_arginfo.h12
-rw-r--r--ext/pdo/tests/pdo_036.phpt4
-rw-r--r--ext/pdo_sqlite/tests/bug44327_2.phpt4
5 files changed, 26 insertions, 16 deletions
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index c7d44028c2..cadfd664b8 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -2262,7 +2262,9 @@ static zval *row_prop_read(zend_object *object, zend_string *name, int type, voi
ZEND_ASSERT(stmt);
ZVAL_NULL(rv);
- if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
+ if (zend_string_equals_literal(name, "queryString")) {
+ return zend_std_read_property(&stmt->std, name, type, cache_slot, rv);
+ } else if (is_numeric_string(ZSTR_VAL(name), ZSTR_LEN(name), &lval, NULL, 0) == IS_LONG) {
if (lval >= 0 && lval < stmt->column_count) {
fetch_value(stmt, rv, lval, NULL);
}
@@ -2275,9 +2277,6 @@ static zval *row_prop_read(zend_object *object, zend_string *name, int type, voi
return rv;
}
}
- if (zend_string_equals_literal(name, "queryString")) {
- return zend_std_read_property(&stmt->std, name, type, cache_slot, rv);
- }
}
return rv;
@@ -2306,6 +2305,10 @@ static zval *row_dim_read(zend_object *object, zval *member, int type, zval *rv)
return &EG(uninitialized_zval);
}
+ if (zend_string_equals_literal(Z_STR_P(member), "queryString")) {
+ return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv);
+ }
+
/* TODO: replace this with a hash of available column names to column
* numbers */
for (colno = 0; colno < stmt->column_count; colno++) {
@@ -2314,9 +2317,6 @@ static zval *row_dim_read(zend_object *object, zval *member, int type, zval *rv)
return rv;
}
}
- if (zend_string_equals_literal(Z_STR_P(member), "queryString")) {
- return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv);
- }
}
return rv;
@@ -2428,6 +2428,10 @@ static HashTable *row_get_properties_for(zend_object *object, zend_prop_purpose
}
props = zend_array_dup(stmt->std.properties);
for (i = 0; i < stmt->column_count; i++) {
+ if (zend_string_equals_literal(stmt->columns[i].name, "queryString")) {
+ continue;
+ }
+
zval val;
fetch_value(stmt, &val, i, NULL);
diff --git a/ext/pdo/pdo_stmt.stub.php b/ext/pdo/pdo_stmt.stub.php
index 856232e796..18e79e56b9 100644
--- a/ext/pdo/pdo_stmt.stub.php
+++ b/ext/pdo/pdo_stmt.stub.php
@@ -4,8 +4,7 @@
class PDOStatement implements IteratorAggregate
{
- /** @var string|null */
- public $queryString;
+ public string $queryString;
/** @return bool */
public function bindColumn(string|int $column, mixed &$var, int $type = 0, int $maxLength = 0, mixed $driverOptions = null) {}
@@ -69,4 +68,5 @@ class PDOStatement implements IteratorAggregate
final class PDORow
{
+ public string $queryString;
}
diff --git a/ext/pdo/pdo_stmt_arginfo.h b/ext/pdo/pdo_stmt_arginfo.h
index bccf354b88..282938f52a 100644
--- a/ext/pdo/pdo_stmt_arginfo.h
+++ b/ext/pdo/pdo_stmt_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: d25ba8b84022d6c6208dd45412772d72196c934f */
+ * Stub hash: 1b8043ec5e3e621819c85828daf9316136fef62e */
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindColumn, 0, 0, 2)
ZEND_ARG_TYPE_MASK(0, column, MAY_BE_STRING|MAY_BE_LONG, NULL)
@@ -144,9 +144,9 @@ static zend_class_entry *register_class_PDOStatement(zend_class_entry *class_ent
zend_class_implements(class_entry, 1, class_entry_IteratorAggregate);
zval property_queryString_default_value;
- ZVAL_NULL(&property_queryString_default_value);
+ ZVAL_UNDEF(&property_queryString_default_value);
zend_string *property_queryString_name = zend_string_init("queryString", sizeof("queryString") - 1, 1);
- zend_declare_property_ex(class_entry, property_queryString_name, &property_queryString_default_value, ZEND_ACC_PUBLIC, NULL);
+ zend_declare_typed_property(class_entry, property_queryString_name, &property_queryString_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
zend_string_release(property_queryString_name);
return class_entry;
@@ -160,5 +160,11 @@ static zend_class_entry *register_class_PDORow(void)
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL;
+ zval property_queryString_default_value;
+ ZVAL_UNDEF(&property_queryString_default_value);
+ zend_string *property_queryString_name = zend_string_init("queryString", sizeof("queryString") - 1, 1);
+ zend_declare_typed_property(class_entry, property_queryString_name, &property_queryString_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
+ zend_string_release(property_queryString_name);
+
return class_entry;
}
diff --git a/ext/pdo/tests/pdo_036.phpt b/ext/pdo/tests/pdo_036.phpt
index 21c8241c99..e27cc253ee 100644
--- a/ext/pdo/tests/pdo_036.phpt
+++ b/ext/pdo/tests/pdo_036.phpt
@@ -15,9 +15,9 @@ var_dump($x);
?>
--EXPECTF--
-object(PDOStatement)#%d (1) {
+object(PDOStatement)#%d (0) {
["queryString"]=>
- NULL
+ uninitialized(string)
}
Fatal error: Uncaught PDOException: You may not create a PDORow manually in %spdo_036.php:8
diff --git a/ext/pdo_sqlite/tests/bug44327_2.phpt b/ext/pdo_sqlite/tests/bug44327_2.phpt
index a9b428b2cc..7229e41a2f 100644
--- a/ext/pdo_sqlite/tests/bug44327_2.phpt
+++ b/ext/pdo_sqlite/tests/bug44327_2.phpt
@@ -45,6 +45,6 @@ object(PDOStatement)#%d (1) {
string(23) "select 1 as queryString"
object(PDORow)#%d (1) {
["queryString"]=>
- int(1)
+ string(23) "select 1 as queryString"
}
-int(1)
+string(23) "select 1 as queryString"