-
Couldn't load subscription status.
- Fork 8k
ext/pgsql: php_pgsql_convert converts E_NOTICE to TypeError exceptions. #11238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4529,7 +4529,6 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * | |||||||||||||||||||||
| data_type = php_pgsql_get_data_type(Z_STR_P(type)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /* TODO: Should E_NOTICE be converted to type error if PHP type cannot be converted to field type? */ | ||||||||||||||||||||||
| switch(data_type) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| case PG_BOOL: | ||||||||||||||||||||||
|
|
@@ -4554,7 +4553,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * | |||||||||||||||||||||
| ZVAL_STRINGL(&new_val, "'f'", sizeof("'f'")-1); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| else { | ||||||||||||||||||||||
| php_error_docref(NULL, E_NOTICE, "Detected invalid value (%s) for PostgreSQL %s field (%s)", Z_STRVAL_P(val), Z_STRVAL_P(type), ZSTR_VAL(field)); | ||||||||||||||||||||||
| zend_value_error("%s(): Field \"%s\" must be of type bool, %s (%s) given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type), Z_STRVAL_P(val)); | ||||||||||||||||||||||
| err = 1; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -4586,7 +4585,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| PGSQL_CONV_CHECK_IGNORE(); | ||||||||||||||||||||||
| if (err) { | ||||||||||||||||||||||
| php_error_docref(NULL, E_NOTICE, "Expects string, null, long or boolelan value for PostgreSQL '%s' (%s)", Z_STRVAL_P(type), ZSTR_VAL(field)); | ||||||||||||||||||||||
| zend_type_error("%s(): Field \"%s\" must be of type string|null|long|bool, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); | ||||||||||||||||||||||
|
||||||||||||||||||||||
| zend_type_error("%s(): Field \"%s\" must be of type string|null|long|bool, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); | |
| zend_type_error("%s(): Field \"%s\" must be of type string|null|int|bool, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this field types just wants am int|null and does some type juggling to convert other types to int. however this maybe should follow the normal PHP semantics
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, it seems it only wants a float. But then this might require us to split the logic for NUMERIC and MONEY fields
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| zend_type_error("%s(): Field \"%s\" must be of type string|null|long|float, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); | |
| zend_type_error("%s(): Field \"%s\" must be of type string|null, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); |
Similarly here, it does implicit type juggling to end up with a string.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only just saw that "long" is used instead of the standard "int" PHP type.
Also it wants the time as an int so...
Moreover, there is the issue again about not actually providing the type of the actual passed value
| zend_type_error("%s(): Field \"%s\" must be of type string|null|long|float, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); | |
| zend_type_error("%s(): Field \"%s\" must be of type int|null, %s given", get_active_function_name(), ZSTR_VAL(field), zend_zval_value_name(val)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (err == 2) { | |
| zend_value_error("%s(): Field \"%s\" must be of type IPv4|IPv6|null, given %s", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(val)); | |
| } else { | |
| zend_type_error("%s(): Field \"%s\" must be of type IPv4|IPv6|null, given %s", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); | |
| } | |
| if (err == 2) { | |
| zend_value_error("%s(): Field \"%s\" must be a valid IPv4 or IPv6 address string, \"%s\" given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(val)); | |
| } else { | |
| zend_type_error("%s(): Field \"%s\" must be of type string|null, given %s", get_active_function_name(), ZSTR_VAL(field), zend_zval_value_name(val)); | |
| } |
As far as I can see the "type" zval should have nothing to do here. I think ideally it would be good to have a new test that tries to hit everyone of these type errors and value errors as it would be easier to see and correct the error messages.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| zend_type_error("%s(): Field \"%s\" must be of type string|null|long|float, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); | |
| zend_type_error("%s(): Field \"%s\" must be of type string|null, %s given", get_active_function_name(), ZSTR_VAL(field), Z_STRVAL_P(type)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,18 @@ pg_query($db, "CREATE TABLE bug77047 ( | |
| t TIME WITHOUT TIME ZONE | ||
| )"); | ||
|
|
||
| pg_insert($db, "bug77047", array("t" => "13:31")); | ||
| try { | ||
| pg_insert($db, "bug77047", array("t" => "13:31")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage(); | ||
| } | ||
| pg_insert($db, "bug77047", array("t" => "13:31:13")); | ||
| pg_insert($db, "bug77047", array("t" => "1:2:3")); | ||
| pg_insert($db, "bug77047", array("t" => "xyz")); | ||
| try { | ||
| pg_insert($db, "bug77047", array("t" => "xyz")); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . PHP_EOL; | ||
| } | ||
| pg_insert($db, "bug77047", array("t" => NULL)); | ||
| pg_insert($db, "bug77047", array("t" => "")); | ||
|
|
||
|
|
@@ -33,10 +41,9 @@ while (false !== ($row = pg_fetch_row($res))) { | |
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Notice: pg_insert(): Expects NULL or string for PostgreSQL time field (t) in %s on line %d | ||
| pg_insert(): Field "t" must be of type string|null, time given | ||
| string(8) "13:31:00" | ||
| string(8) "13:31:13" | ||
| string(8) "01:02:03" | ||
| NULL | ||
| NULL | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erf I don't know what to do with this error message as what it wants is a valid PostgreSQL bool and we are parsing the string here...