Skip to content

ext/phar: reclassify various exception#21766

Open
Girgias wants to merge 4 commits intophp:masterfrom
Girgias:2026-04-phar-reclassify-exceptions
Open

ext/phar: reclassify various exception#21766
Girgias wants to merge 4 commits intophp:masterfrom
Girgias:2026-04-phar-reclassify-exceptions

Conversation

@Girgias
Copy link
Copy Markdown
Member

@Girgias Girgias commented Apr 15, 2026

Main purpose is to use ValueError/TypeError in cases that are about value/type validation. This fixes the wording to match the more usual wording.

Secondly use Error when an object is not initialized or one attemps to call the constructor twice, similar to other extensions

We also fix some of the phar test stubs. Which we regenerate by running the .phar.inc file.

Main purpose is to use ValueError/TypeError in cases that are about value/type validation.
This fixes the wording to match the more usual wording.

Secondly use Error when an object is not initialized or one attemps to call the constructor twice, similar to other extensions
Girgias added 3 commits April 15, 2026 18:20
TODO: It seems like one needs to copy the files from ext/phar/tests/files/ to ext/phar/tests/cache_list/files/ and that they were out of sync
@Girgias Girgias marked this pull request as ready for review April 16, 2026 18:57
@Girgias Girgias requested a review from kocsismate as a code owner April 16, 2026 18:57
@Girgias Girgias requested a review from TimWolla April 16, 2026 18:57
Comment thread ext/phar/phar_object.c
ZVAL_DEREF(data);
if (Z_TYPE_P(data) != IS_STRING) {
zend_throw_exception_ex(phar_ce_PharException, 0, "Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME");
zend_argument_type_error(1, "must be an array of string types, %s given", zend_zval_value_name(data));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be pedantic, array of strings? It doesn't contain types.

Comment thread ext/phar/phar_object.c

if ((index || webindex) && (phar_obj->archive->is_tar || phar_obj->archive->is_zip)) {
zend_argument_value_error(index ? 1 : 2, "must be null for a tar- or zip-based phar stub, string given");
zend_argument_type_error(index ? 1 : 2, "must be null for a tar- or zip-based phar stub, string given");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems a bit unnecessary. I think type errors mostly apply to signatures, whereas this is a logical issue.

Comment thread ext/phar/phar_object.c
if (files_ht && UNEXPECTED(zend_hash_num_elements(files_ht) == 0)) {
zend_argument_must_not_be_empty_error(2);
} else if (filename && UNEXPECTED(ZSTR_LEN(filename) == 0)) {
zend_argument_must_not_be_empty_error(2);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branches can be combined.

Comment thread ext/phar/phar_object.c

php_stream_close(fp);
if (files_ht && UNEXPECTED(zend_hash_num_elements(files_ht) == 0)) {
zend_argument_must_not_be_empty_error(2);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing RETURN_THROWS();.

Comment thread ext/phar/phar_object.c
/* TODO: This error message is nonsensical */
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
"Invalid argument, extraction path must be non-zero length");
"Invalid argument, %s cannot be found", phar_obj->archive->fname);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "opened" instead of "found", but I don't know all the reasons for which this can fail.

Comment thread ext/phar/phar_object.c
if (IS_STRING != Z_TYPE_P(zval_file)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
"Invalid argument, array of filenames to extract contains non-string value");
zend_argument_type_error(2, "must be an array of string elements, %s given", zend_zval_value_name(zval_file));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent with the above, maybe just "array of strings".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants