Skip to content

Commit

Permalink
Make Phar $fileNotFoundScript nullable
Browse files Browse the repository at this point in the history
While "" is already treated the same way as absence, null is the
logically correct default here. Making this one argument non-nullable
is particularly pecular when considering that the preceding $alias
and $index arguments are both nullable.
  • Loading branch information
nikic committed Feb 9, 2021
1 parent 3549f48 commit 44192ce
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ PHP_METHOD(Phar, webPhar)
phar_entry_info *info = NULL;
size_t sapi_mod_name_len = strlen(sapi_module.name);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!saf!", &alias, &alias_len, &index_php, &index_php_len, &f404, &f404_len, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!af!", &alias, &alias_len, &index_php, &index_php_len, &f404, &f404_len, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) {
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/phar/phar_object.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ final public static function mungServer(array $variables): void {}
final public static function unlinkArchive(string $filename): bool {}

final public static function webPhar(
?string $alias = null, ?string $index = null, string $fileNotFoundScript = "",
?string $alias = null, ?string $index = null, ?string $fileNotFoundScript = null,
array $mimeTypes = [], ?callable $rewrite = null): void {}
}

Expand Down Expand Up @@ -470,7 +470,7 @@ final public static function unlinkArchive(string $filename): bool {}

/** @implementation-alias Phar::webPhar */
final public static function webPhar(
?string $alias = null, ?string $index = null, string $fileNotFoundScript = "",
?string $alias = null, ?string $index = null, ?string $fileNotFoundScript = null,
array $mimeTypes = [], ?callable $rewrite = null): void {}
}

Expand Down
4 changes: 2 additions & 2 deletions ext/phar/phar_object_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 3575a0330ff6102461655bc84add44e8b08b585f */
* Stub hash: a8562e63010e127aadb97134733ac328ced3c7bf */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Phar___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
Expand Down Expand Up @@ -204,7 +204,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Phar_webPhar, 0, 0, IS_VOID, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, alias, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, index, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fileNotFoundScript, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fileNotFoundScript, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mimeTypes, IS_ARRAY, 0, "[]")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, rewrite, IS_CALLABLE, 1, "null")
ZEND_END_ARG_INFO()
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/tests/cache_list/frontcontroller12.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.php:2
Stack trace:
#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller12.php on line 2
2 changes: 1 addition & 1 deletion ext/phar/tests/cache_list/frontcontroller13.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.php:2
Stack trace:
#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller13.php on line 2
2 changes: 1 addition & 1 deletion ext/phar/tests/cache_list/frontcontroller31.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ files/frontcontroller16.phar
--EXPECTF--
Fatal error: Uncaught TypeError: Phar::webPhar(): Argument #5 ($rewrite) must be a valid callback or null, class "fail" not found in %s:%d
Stack trace:
#0 %s(%d): Phar::webPhar('test.phar', '/index.php', '', Array, Array)
#0 %s(%d): Phar::webPhar('test.phar', '/index.php', NULL, Array, Array)
#1 {main}
thrown in %s on line %d
2 changes: 1 addition & 1 deletion ext/phar/tests/frontcontroller12.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.php:2
Stack trace:
#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller12.php on line 2
2 changes: 1 addition & 1 deletion ext/phar/tests/frontcontroller13.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.php:2
Stack trace:
#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller13.php on line 2
2 changes: 1 addition & 1 deletion ext/phar/tests/frontcontroller31.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ files/frontcontroller16.phar
--EXPECTF--
Fatal error: Uncaught TypeError: Phar::webPhar(): Argument #5 ($rewrite) must be a valid callback or null, class "fail" not found in %s:%d
Stack trace:
#0 %s(%d): Phar::webPhar('test.phar', '/index.php', '', Array, Array)
#0 %s(%d): Phar::webPhar('test.phar', '/index.php', NULL, Array, Array)
#1 {main}
thrown in %s on line %d
2 changes: 1 addition & 1 deletion ext/phar/tests/tar/frontcontroller12.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.phar.php:2
Stack trace:
#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller12.phar.php on line 2
2 changes: 1 addition & 1 deletion ext/phar/tests/tar/frontcontroller13.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.phar.php:2
Stack trace:
#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller13.phar.php on line 2
2 changes: 1 addition & 1 deletion ext/phar/tests/zip/frontcontroller12.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.phar.php:2
Stack trace:
#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller12.phar.php on line 2
2 changes: 1 addition & 1 deletion ext/phar/tests/zip/frontcontroller13.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.phar.php:2
Stack trace:
#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
#1 {main}
thrown in %sfrontcontroller13.phar.php on line 2

0 comments on commit 44192ce

Please sign in to comment.