Skip to content

Commit 827f30b

Browse files
committed
Declare OCICollection collection property
1 parent 3dbb05e commit 827f30b

File tree

4 files changed

+22
-48
lines changed

4 files changed

+22
-48
lines changed

ext/oci8/oci8.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ public function free(): bool {}
682682
}
683683

684684
class OCICollection {
685+
/** @var resource */
686+
public readonly $collection;
685687
/**
686688
* @alias oci_free_collection
687689
* @tentative-return-type

ext/oci8/oci8_arginfo.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/oci8/oci8_interface.c

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#endif
4242

4343
#define Z_OCILOB_DESCRIPTOR_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0)
44+
#define Z_OCICOLLECTION_COLLECTION_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0)
4445

4546
#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
4647

@@ -2014,11 +2015,7 @@ PHP_FUNCTION(oci_free_collection)
20142015
RETURN_THROWS();
20152016
}
20162017

2017-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
2018-
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
2019-
RETURN_FALSE;
2020-
}
2021-
2018+
tmp = Z_OCICOLLECTION_COLLECTION_P(z_collection);
20222019
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
20232020

20242021
zend_list_close(collection->id);
@@ -2038,11 +2035,7 @@ PHP_FUNCTION(oci_collection_append)
20382035
RETURN_THROWS();
20392036
}
20402037

2041-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
2042-
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
2043-
RETURN_FALSE;
2044-
}
2045-
2038+
tmp = Z_OCICOLLECTION_COLLECTION_P(z_collection);
20462039
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
20472040

20482041
if (php_oci_collection_append(collection, value, (int) value_len)) {
@@ -2063,11 +2056,7 @@ PHP_FUNCTION(oci_collection_element_get)
20632056
RETURN_THROWS();
20642057
}
20652058

2066-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
2067-
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
2068-
RETURN_FALSE;
2069-
}
2070-
2059+
tmp = Z_OCICOLLECTION_COLLECTION_P(z_collection);
20712060
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
20722061

20732062
if (php_oci_collection_element_get(collection, element_index, return_value)) {
@@ -2086,16 +2075,8 @@ PHP_FUNCTION(oci_collection_assign)
20862075
RETURN_THROWS();
20872076
}
20882077

2089-
if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_collection_dest), "collection", sizeof("collection")-1)) == NULL) {
2090-
php_error_docref(NULL, E_WARNING, "Unable to find collection property. The first argument should be valid collection object");
2091-
RETURN_FALSE;
2092-
}
2093-
2094-
if ((tmp_from = zend_hash_str_find(Z_OBJPROP_P(z_collection_from), "collection", sizeof("collection")-1)) == NULL) {
2095-
php_error_docref(NULL, E_WARNING, "Unable to find collection property. The second argument should be valid collection object");
2096-
RETURN_FALSE;
2097-
}
2098-
2078+
tmp_dest = Z_OCICOLLECTION_COLLECTION_P(z_collection_dest);
2079+
tmp_from = Z_OCICOLLECTION_COLLECTION_P(z_collection_from);
20992080
PHP_OCI_ZVAL_TO_COLLECTION(tmp_dest, collection_dest);
21002081
PHP_OCI_ZVAL_TO_COLLECTION(tmp_from, collection_from);
21012082

@@ -2119,11 +2100,7 @@ PHP_FUNCTION(oci_collection_element_assign)
21192100
RETURN_THROWS();
21202101
}
21212102

2122-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
2123-
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
2124-
RETURN_FALSE;
2125-
}
2126-
2103+
tmp = Z_OCICOLLECTION_COLLECTION_P(z_collection);
21272104
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
21282105

21292106
if (php_oci_collection_element_set(collection, element_index, value, (int) value_len)) {
@@ -2144,11 +2121,7 @@ PHP_FUNCTION(oci_collection_size)
21442121
RETURN_THROWS();
21452122
}
21462123

2147-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
2148-
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
2149-
RETURN_FALSE;
2150-
}
2151-
2124+
tmp = Z_OCICOLLECTION_COLLECTION_P(z_collection);
21522125
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
21532126

21542127
if (php_oci_collection_size(collection, &size)) {
@@ -2169,11 +2142,7 @@ PHP_FUNCTION(oci_collection_max)
21692142
RETURN_THROWS();
21702143
}
21712144

2172-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
2173-
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
2174-
RETURN_FALSE;
2175-
}
2176-
2145+
tmp = Z_OCICOLLECTION_COLLECTION_P(z_collection);
21772146
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
21782147

21792148
if (php_oci_collection_max(collection, &max)) {
@@ -2194,11 +2163,7 @@ PHP_FUNCTION(oci_collection_trim)
21942163
RETURN_THROWS();
21952164
}
21962165

2197-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
2198-
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
2199-
RETURN_FALSE;
2200-
}
2201-
2166+
tmp = Z_OCICOLLECTION_COLLECTION_P(z_collection);
22022167
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
22032168

22042169
if (php_oci_collection_trim(collection, trim_size)) {
@@ -2225,7 +2190,7 @@ PHP_FUNCTION(oci_new_collection)
22252190

22262191
if ( (collection = php_oci_collection_create(connection, tdo, (int) tdo_len, schema, (int) schema_len)) ) {
22272192
object_init_ex(return_value, oci_coll_class_entry_ptr);
2228-
add_property_resource(return_value, "collection", collection->id);
2193+
ZVAL_RES(Z_OCICOLLECTION_COLLECTION_P(return_value), collection->id);
22292194
}
22302195
else {
22312196
RETURN_FALSE;

ext/oci8/oci8_statement.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef ub4 oci_phpsized_int;
4343
#endif
4444

4545
#define Z_OCILOB_DESCRIPTOR_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0)
46+
#define Z_OCICOLLECTION_COLLECTION_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0)
4647

4748
/* {{{ php_oci_statement_create()
4849
Create statemend handle and allocate necessary resources */
@@ -1141,7 +1142,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l
11411142
{
11421143
zval *tmp;
11431144

1144-
if (Z_TYPE_P(param) != IS_OBJECT || (tmp = zend_hash_str_find(Z_OBJPROP_P(param), "collection", sizeof("collection")-1)) == NULL) {
1145+
if (Z_TYPE_P(param) != IS_OBJECT || !(tmp = Z_OCICOLLECTION_COLLECTION_P(param))) {
11451146
php_error_docref(NULL, E_WARNING, "Unable to find collection property");
11461147
return 1;
11471148
}

0 commit comments

Comments
 (0)