Skip to content

Commit 793e5a5

Browse files
committed
Promote some warnings to ValueError in OCI8
1 parent 3854234 commit 793e5a5

File tree

3 files changed

+54
-64
lines changed

3 files changed

+54
-64
lines changed

ext/oci8/oci8.stub.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,14 @@ function oci_get_implicit_resultset($statement_resource) {}
412412
/**
413413
* @param resource $statement_resource
414414
*/
415-
function oci_set_prefetch($statement_resource, int $number_of_rows): ?bool {}
415+
function oci_set_prefetch($statement_resource, int $number_of_rows): bool {}
416416

417417
/**
418418
* @param resource $statement_resource
419419
* @alias oci_set_prefetch
420420
* @deprecated
421421
*/
422-
function ocisetprefetch($statement_resource, int $number_of_rows): ?bool {}
422+
function ocisetprefetch($statement_resource, int $number_of_rows): bool {}
423423

424424
/**
425425
* @param resource $connection_resource

ext/oci8/oci8_arginfo.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 2d553815c21edd58bc29b1ca8d294d5750fd7312 */
2+
* Stub hash: b795b3009f220d578fc93134bd9f07dd685b6493 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_define_by_name, 0, 3, _IS_BOOL, 0)
55
ZEND_ARG_INFO(0, statement_resource)
@@ -292,7 +292,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_get_implicit_resultset, 0, 0, 1)
292292
ZEND_ARG_INFO(0, statement_resource)
293293
ZEND_END_ARG_INFO()
294294

295-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 1)
295+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 0)
296296
ZEND_ARG_INFO(0, statement_resource)
297297
ZEND_ARG_TYPE_INFO(0, number_of_rows, IS_LONG, 0)
298298
ZEND_END_ARG_INFO()

ext/oci8/oci8_interface.c

+50-60
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ PHP_FUNCTION(oci_define_by_name)
109109
ZEND_PARSE_PARAMETERS_END();
110110

111111
if (!name_len) {
112-
php_error_docref(NULL, E_WARNING, "Column name cannot be empty");
113-
RETURN_FALSE;
112+
zend_argument_value_error(2, "cannot be empty");
113+
RETURN_THROWS();
114114
}
115115

116116
PHP_OCI_ZVAL_TO_STATEMENT(stmt, statement);
@@ -210,8 +210,8 @@ PHP_FUNCTION(oci_bind_array_by_name)
210210
}
211211

212212
if (max_array_len <= 0) {
213-
php_error_docref(NULL, E_WARNING, "Maximum array length must be greater than zero");
214-
RETURN_FALSE;
213+
zend_argument_value_error(4, "must be greater than 0");
214+
RETURN_THROWS();
215215
}
216216

217217
if (php_oci_bind_array_by_name(statement, name, (sb4) name_len, bind_var, max_array_len, max_item_len, type)) {
@@ -257,18 +257,18 @@ PHP_FUNCTION(oci_lob_save)
257257
RETURN_THROWS();
258258
}
259259

260+
if (offset < 0) {
261+
zend_argument_value_error(3, "must be greater than or equal to 0");
262+
RETURN_THROWS();
263+
}
264+
260265
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
261266
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
262267
RETURN_FALSE;
263268
}
264269

265270
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
266271

267-
if (offset < 0) {
268-
php_error_docref(NULL, E_WARNING, "Offset parameter must be greater than or equal to 0");
269-
RETURN_FALSE;
270-
}
271-
272272
if (php_oci_lob_write(descriptor, (ub4) offset, data, (ub4) data_len, &bytes_written)) {
273273
RETURN_FALSE;
274274
}
@@ -284,7 +284,7 @@ PHP_FUNCTION(oci_lob_import)
284284
char *filename;
285285
size_t filename_len;
286286

287-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
287+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
288288
RETURN_THROWS();
289289
}
290290

@@ -293,11 +293,6 @@ PHP_FUNCTION(oci_lob_import)
293293
RETURN_FALSE;
294294
}
295295

296-
if (CHECK_NULL_PATH(filename, filename_len)) {
297-
php_error_docref(NULL, E_WARNING, "filename must not contain null bytes");
298-
RETURN_FALSE;
299-
}
300-
301296
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
302297

303298
if (php_oci_lob_import(descriptor, filename)) {
@@ -354,18 +349,18 @@ PHP_FUNCTION(oci_lob_read)
354349
RETURN_THROWS();
355350
}
356351

352+
if (length <= 0) {
353+
zend_argument_value_error(2, "must be greater than 0");
354+
RETURN_THROWS();
355+
}
356+
357357
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
358358
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
359359
RETURN_FALSE;
360360
}
361361

362362
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
363363

364-
if (length <= 0) {
365-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
366-
RETURN_FALSE;
367-
}
368-
369364
if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len)) {
370365
RETURN_FALSE;
371366
}
@@ -604,13 +599,13 @@ PHP_FUNCTION(oci_lob_truncate)
604599
RETURN_THROWS();
605600
}
606601

607-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
608-
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
609-
RETURN_FALSE;
602+
if (trim_length < 0) {
603+
zend_argument_value_error(2, "must be greater than or equal to zero");
604+
RETURN_THROWS();
610605
}
611606

612-
if (trim_length < 0) {
613-
php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to zero");
607+
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
608+
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
614609
RETURN_FALSE;
615610
}
616611

@@ -640,15 +635,15 @@ PHP_FUNCTION(oci_lob_erase)
640635
if (offset_is_null) {
641636
offset = -1;
642637
} else if (offset < 0) {
643-
php_error_docref(NULL, E_WARNING, "Offset must be greater than or equal to 0");
644-
RETURN_FALSE;
638+
zend_argument_value_error(2, "must be greater than or equal to 0");
639+
RETURN_THROWS();
645640
}
646641

647642
if (length_is_null) {
648643
length = -1;
649644
} else if (length < 0) {
650-
php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0");
651-
RETURN_FALSE;
645+
zend_argument_value_error(3, "must be greater than or equal to 0");
646+
RETURN_THROWS();
652647
}
653648

654649
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
@@ -756,6 +751,13 @@ PHP_FUNCTION(oci_lob_copy)
756751
RETURN_THROWS();
757752
}
758753

754+
if (length_is_null) {
755+
length = -1;
756+
} else if (length < 0) {
757+
zend_argument_value_error(3, "must be greater than or equal to 0");
758+
RETURN_THROWS();
759+
}
760+
759761
if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor")-1)) == NULL) {
760762
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
761763
RETURN_FALSE;
@@ -769,13 +771,6 @@ PHP_FUNCTION(oci_lob_copy)
769771
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_dest, descriptor_dest);
770772
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_from, descriptor_from);
771773

772-
if (length_is_null) {
773-
length = -1;
774-
} else if (length < 0) {
775-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
776-
RETURN_FALSE;
777-
}
778-
779774
if (php_oci_lob_copy(descriptor_dest, descriptor_from, length)) {
780775
RETURN_FALSE;
781776
}
@@ -831,34 +826,29 @@ PHP_FUNCTION(oci_lob_export)
831826
php_stream *stream;
832827
ub4 lob_length;
833828

834-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &start_is_null, &length, &length_is_null) == FAILURE) {
829+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &start_is_null, &length, &length_is_null) == FAILURE) {
835830
RETURN_THROWS();
836831
}
837832

838833
if (start_is_null) {
839834
start = -1;
840835
} else if (start < 0) {
841-
php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0");
842-
RETURN_FALSE;
836+
zend_argument_value_error(3, "must be greater than or equal to 0");
837+
RETURN_THROWS();
843838
}
844839

845840
if (length_is_null) {
846841
length = -1;
847842
} else if (length < 0) {
848-
php_error_docref(NULL, E_WARNING, "length parameter must be greater than or equal to 0");
849-
RETURN_FALSE;
843+
zend_argument_value_error(4, "must be greater than or equal to 0");
844+
RETURN_THROWS();
850845
}
851846

852847
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
853848
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
854849
RETURN_FALSE;
855850
}
856851

857-
if (CHECK_NULL_PATH(filename, filename_len)) {
858-
php_error_docref(NULL, E_WARNING, "filename must not contain null bytes");
859-
RETURN_FALSE;
860-
}
861-
862852
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
863853

864854
if (php_oci_lob_get_length(descriptor, &lob_length)) {
@@ -1630,8 +1620,8 @@ PHP_FUNCTION(oci_set_prefetch)
16301620
PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
16311621

16321622
if (size < 0) {
1633-
php_error_docref(NULL, E_WARNING, "Number of rows to be prefetched has to be greater than or equal to 0");
1634-
return;
1623+
zend_argument_value_error(2, "must be greater than or equal to 0");
1624+
RETURN_THROWS();
16351625
}
16361626

16371627
if (php_oci_statement_set_prefetch(statement, (ub4)size)) {
@@ -1899,16 +1889,16 @@ PHP_FUNCTION(oci_password_change)
18991889
PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
19001890

19011891
if (!user_len) {
1902-
php_error_docref(NULL, E_WARNING, "Username cannot be empty");
1903-
RETURN_FALSE;
1892+
zend_argument_value_error(2, "cannot be empty");
1893+
RETURN_THROWS();
19041894
}
19051895
if (!pass_old_len) {
1906-
php_error_docref(NULL, E_WARNING, "Old password cannot be empty");
1907-
RETURN_FALSE;
1896+
zend_argument_value_error(3, "cannot be empty");
1897+
RETURN_THROWS();
19081898
}
19091899
if (!pass_new_len) {
1910-
php_error_docref(NULL, E_WARNING, "New password cannot be empty");
1911-
RETURN_FALSE;
1900+
zend_argument_value_error(4, "cannot be empty");
1901+
RETURN_THROWS();
19121902
}
19131903

19141904
if (php_oci_password_change(connection, user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len)) {
@@ -1918,16 +1908,16 @@ PHP_FUNCTION(oci_password_change)
19181908
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "ssss", &dbname, &dbname_len, &user, &user_len, &pass_old, &pass_old_len, &pass_new, &pass_new_len) == SUCCESS) {
19191909

19201910
if (!user_len) {
1921-
php_error_docref(NULL, E_WARNING, "Username cannot be empty");
1922-
RETURN_FALSE;
1911+
zend_argument_value_error(2, "cannot be empty");
1912+
RETURN_THROWS();
19231913
}
19241914
if (!pass_old_len) {
1925-
php_error_docref(NULL, E_WARNING, "Old password cannot be empty");
1926-
RETURN_FALSE;
1915+
zend_argument_value_error(3, "cannot be empty");
1916+
RETURN_THROWS();
19271917
}
19281918
if (!pass_new_len) {
1929-
php_error_docref(NULL, E_WARNING, "New password cannot be empty");
1930-
RETURN_FALSE;
1919+
zend_argument_value_error(4, "cannot be empty");
1920+
RETURN_THROWS();
19311921
}
19321922

19331923
connection = php_oci_do_connect_ex(user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len, dbname, (int) dbname_len, NULL, OCI_DEFAULT, 0, 0);

0 commit comments

Comments
 (0)