Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 67 additions & 75 deletions ext/phar/phar_object.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ext/phar/phar_object.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function delete(string $localName): true {}
public function delMetadata(): true {}

/** @tentative-return-type */
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): bool {}
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): true {}

/** @tentative-return-type */
public function getAlias(): ?string {}
Expand Down Expand Up @@ -345,7 +345,7 @@ public function delMetadata(): true {}
* @tentative-return-type
* @implementation-alias Phar::extractTo
*/
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): bool {}
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): true {}

/**
* @tentative-return-type
Expand Down
4 changes: 2 additions & 2 deletions ext/phar/phar_object_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ext/phar/tests/030.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ require $pname . '/a.php';
$p = new Phar($fname);
var_dump(isset($p['.phar/test']));
try {
$p['.phar/test'];
} catch (Exception $e) {
echo $e->getMessage(),"\n";
$p['.phar/test'];
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage() . "\n";
}
?>
--CLEAN--
Expand All @@ -43,4 +43,4 @@ This is b/c
This is b/d
This is e
bool(false)
Cannot directly get any files or directories in magic ".phar" directory
ValueError: Phar::offsetGet(): Argument #1 ($localName) must not start with ".phar"
14 changes: 10 additions & 4 deletions ext/phar/tests/bug54289.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ var_dump(is_dir($outDir.DIRECTORY_SEPARATOR.'dirAB'));
try {
$pharB->extractTo($outDir, 'dirX/', true);
echo 'failed to throw expected exception';
} catch (PharException $ex) {
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage() . "\n";
}

// should also not be able to pull out /, because paths are not "rooted" that way
try {
$pharB->extractTo($outDir, '/', true);
echo 'failed to throw expected exception';
} catch (PharException $ex) {
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage() . "\n";
}

// should be able to do by array, too
Expand All @@ -45,7 +47,8 @@ try {
$pharB = new Phar($phar);
$pharB->extractTo($outDir, [ 'dirA/', 'dirX/' ], true);
echo 'failed to throw expected exception';
} catch (PharException $ex) {
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage() . "\n";
}

echo 'done';
Expand All @@ -63,8 +66,11 @@ foreach ($iter as $value) {
$value->isFile() ? unlink($value) : rmdir($value);
}
?>
--EXPECT--
--EXPECTF--
bool(true)
bool(true)
bool(false)
PharException: phar error: attempted to extract non-existent file or directory "dirX/" from phar "%sbug54289/test.phar"
PharException: phar error: attempted to extract non-existent file or directory "/" from phar "%sbug54289/test.phar"
PharException: phar error: attempted to extract non-existent file or directory "dirX/" from phar "%sbug54289/test.phar"
done
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ $workdir = __DIR__.'/getPathname_exception';
[ Found: %shello.txt ]
[getPathname]
string(%d) "%shello.txt"
getPathname() must return a string
MyGlobIterator::getPathname(): Return value must be of type string, null returned
Previous: exception in getPathname()
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ $workdir = __DIR__.'/getPathname_wrong_type';
--EXPECTF--
[ Found: %scontent%chello.txt ]
[getPathname]
getPathname() must return a string
MyGlobIterator::getPathname(): Return value must be of type string, int returned
Binary file modified ext/phar/tests/cache_list/files/frontcontroller10.phar
Binary file not shown.
8 changes: 6 additions & 2 deletions ext/phar/tests/cache_list/files/frontcontroller10.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
var_dump($_SERVER["PHAR_REQUEST_URI"]);
';
$a->setStub('<?php
Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI", "OOPSIE"));
Phar::webPhar();
try {
Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI", "OOPSIE"));
Phar::webPhar();
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller11.phar
Binary file not shown.
8 changes: 6 additions & 2 deletions ext/phar/tests/cache_list/files/frontcontroller11.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
var_dump($_SERVER["PHAR_REQUEST_URI"]);
';
$a->setStub('<?php
Phar::mungServer(array(array(), "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
Phar::webPhar();
try {
Phar::mungServer(array(array(), "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
Phar::webPhar();
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller12.phar
Binary file not shown.
8 changes: 6 additions & 2 deletions ext/phar/tests/cache_list/files/frontcontroller12.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
var_dump($_SERVER["PHAR_REQUEST_URI"]);
';
$a->setStub('<?php
Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
Phar::webPhar();
try {
Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
Phar::webPhar();
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller14.phar
Binary file not shown.
10 changes: 7 additions & 3 deletions ext/phar/tests/cache_list/files/frontcontroller14.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ function s($a)
{
return "/html/index.php";
}
Phar::interceptFileFuncs();
Phar::mungServer(array("PHP_SELF", "REQUEST_URI"));
Phar::webPhar("whatever", "/html/index.php", null, array(), "s");
try {
Phar::interceptFileFuncs();
Phar::mungServer(array("PHP_SELF", "REQUEST_URI"));
Phar::webPhar("whatever", "/html/index.php", null, array(), "s");
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller16.phar
Binary file not shown.
6 changes: 3 additions & 3 deletions ext/phar/tests/cache_list/files/frontcontroller16.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ echo "hi";
';
$a->setStub('<?php
try {
Phar::webPhar("test.phar", "/index.php", null, array(), array("fail", "here"));
} catch (TypeError|Exception $e) {
die($e->getMessage() . "\n");
Phar::webPhar("test.phar", "/index.php", null, array(), array("fail", "here"));
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller17.phar
Binary file not shown.
6 changes: 3 additions & 3 deletions ext/phar/tests/cache_list/files/frontcontroller17.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ echo "hi";
';
$a->setStub('<?php
try {
Phar::webPhar("test.phar", "/index.php", null, array(), function() { throw new Exception; });
} catch (Exception $e) {
die($e->getMessage() . "\n");
Phar::webPhar("test.phar", "/index.php", null, array(), function() { throw new Exception; });
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller18.phar
Binary file not shown.
6 changes: 3 additions & 3 deletions ext/phar/tests/cache_list/files/frontcontroller18.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function s($a)
{
}
try {
Phar::webPhar("test.phar", "/index.php", null, array(), "s");
} catch (Exception $e) {
die($e->getMessage() . "\n");
Phar::webPhar("test.phar", "/index.php", null, array(), "s");
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller19.phar
Binary file not shown.
6 changes: 3 additions & 3 deletions ext/phar/tests/cache_list/files/frontcontroller19.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ echo "another.php\n";
$a->setStub('<?php
set_include_path("phar://" . __FILE__);
try {
Phar::webPhar("test.phar", "/start/index.php");
} catch (Exception $e) {
die($e->getMessage() . "\n");
Phar::webPhar("test.phar", "/start/index.php");
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller3.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion ext/phar/tests/cache_list/files/frontcontroller3.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ function s($a)
if (isset($b[$a])) return $b[$a];
return $a;
}
Phar::webPhar("whatever", "/index.php", null, array(), "s");
try {
Phar::webPhar("whatever", "/index.php", null, array(), "s");
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller4.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion ext/phar/tests/cache_list/files/frontcontroller4.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ function s($a)
if (isset($b[$a])) return $b[$a];
return $a;
}
Phar::webPhar("whatever", "index.php", null, array(), "s");
try {
Phar::webPhar("whatever", "index.php", null, array(), "s");
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller5.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion ext/phar/tests/cache_list/files/frontcontroller5.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ $a['a.php'] = 'hio';
$a['a.jpg'] = 'hio';
$a['a.phps'] = '<?php function hio(){}';
$a->setStub('<?php
Phar::webPhar("whatever", "index.php", null, array(0 => "oops"));
try {
Phar::webPhar("whatever", "index.php", null, array(0 => "oops"));
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller6.phar
Binary file not shown.
8 changes: 6 additions & 2 deletions ext/phar/tests/cache_list/files/frontcontroller6.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ $a['a.php'] = 'hio';
$a['a.jpg'] = 'hio';
$a['a.phps'] = '<?php function hio(){}';
$a->setStub('<?php
Phar::webPhar("whatever", "index.php", null, array("blah" => 100));
try {
Phar::webPhar("whatever", "index.php", null, array("php" => 100));
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
?>
?>
Binary file modified ext/phar/tests/cache_list/files/frontcontroller7.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion ext/phar/tests/cache_list/files/frontcontroller7.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ $a['a.php'] = 'hio';
$a['a.jpg'] = 'hio';
$a['a.phps'] = '<?php function hio(){}';
$a->setStub('<?php
Phar::webPhar("whatever", "index.php", null, array("blah" => null));
try {
Phar::webPhar("whatever", "index.php", null, array("php" => null));
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller8.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion ext/phar/tests/cache_list/files/frontcontroller8.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ $a['unknown.ext'] = '<?php var_dump("hi");';
$a['bigfile.txt'] = str_repeat('a', 8193);
$a['fatalerror.phps'] = '<?php oopsie_daisy();';
$a->setStub('<?php
Phar::webPhar("whatever", "index.php", "404.php", array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
try {
Phar::webPhar("whatever", "index.php", "404.php", array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
Binary file modified ext/phar/tests/cache_list/files/frontcontroller9.phar
Binary file not shown.
8 changes: 6 additions & 2 deletions ext/phar/tests/cache_list/files/frontcontroller9.phar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ $a['a.jpg'] = 'hio2';
$a['a.php'] = '<?php function hio(){}';
$a['fronk.gronk'] = 'hio3';
$a->setStub('<?php
Phar::mungServer(array());
Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
try {
Phar::mungServer(array());
Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
} catch (Throwable $e) {
die($e::class . ": " . $e->getMessage() . "\n");
}
echo "oops did not run\n";
var_dump($_ENV, $_SERVER);
__HALT_COMPILER();');
Expand Down
6 changes: 1 addition & 5 deletions ext/phar/tests/cache_list/frontcontroller12.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ files/frontcontroller6.phar
--EXPECTHEADERS--
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', NULL, Array)
#1 {main}
thrown in %sfrontcontroller12.php on line 2
ValueError: Phar::webPhar(): Argument #4 ($mimeTypes) mime type specifier must be one of Phar::PHP or Phar::PHPS
8 changes: 2 additions & 6 deletions ext/phar/tests/cache_list/frontcontroller13.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ PATH_INFO=/a.php
files/frontcontroller7.phar
--EXPECTHEADERS--
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', NULL, Array)
#1 {main}
thrown in %sfrontcontroller13.php on line 2
--EXPECT--
TypeError: Phar::webPhar(): Argument #4 ($mimeTypes) mime type specifier must be of type string|int, null given
8 changes: 2 additions & 6 deletions ext/phar/tests/cache_list/frontcontroller18.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ REQUEST_URI=/frontcontroller18.php/fronk.gronk
PATH_INFO=/fronk.gronk
--FILE_EXTERNAL--
files/frontcontroller9.phar
--EXPECTF--
Fatal error: Uncaught PharException: No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME in %sfrontcontroller18.php:2
Stack trace:
#0 %sfrontcontroller18.php(2): Phar::mungServer(Array)
#1 {main}
thrown in %sfrontcontroller18.php on line 2
--EXPECT--
ValueError: Phar::mungServer(): Argument #1 ($variables) must not be empty
8 changes: 2 additions & 6 deletions ext/phar/tests/cache_list/frontcontroller19.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ REQUEST_URI=/frontcontroller19.php/
PATH_INFO=/
--FILE_EXTERNAL--
files/frontcontroller10.phar
--EXPECTF--
Fatal error: Uncaught PharException: Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME in %sfrontcontroller19.php:2
Stack trace:
#0 %sfrontcontroller19.php(2): Phar::mungServer(Array)
#1 {main}
thrown in %sfrontcontroller19.php on line 2
--EXPECT--
ValueError: Phar::mungServer(): Argument #1 ($variables) must have at most 4 elements
8 changes: 2 additions & 6 deletions ext/phar/tests/cache_list/frontcontroller20.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ REQUEST_URI=/frontcontroller20.php/
PATH_INFO=/
--FILE_EXTERNAL--
files/frontcontroller11.phar
--EXPECTF--
Fatal error: Uncaught PharException: Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME in %sfrontcontroller20.php:2
Stack trace:
#0 %sfrontcontroller20.php(2): Phar::mungServer(Array)
#1 {main}
thrown in %sfrontcontroller20.php on line 2
--EXPECT--
TypeError: Phar::mungServer(): Argument #1 ($variables) must be an array of string types, array given
8 changes: 2 additions & 6 deletions ext/phar/tests/cache_list/frontcontroller29.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ PATH_INFO=/fatalerror.phps
files/frontcontroller8.phar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught Error: Call to undefined function oopsie_daisy() in phar://%sfatalerror.phps:1
Stack trace:
#0 %s(%d): Phar::webPhar('whatever', 'index.php', '404.php', Array)
#1 {main}
thrown in phar://%sfatalerror.phps on line 1
--EXPECT--
Error: Call to undefined function oopsie_daisy()
8 changes: 2 additions & 6 deletions ext/phar/tests/cache_list/frontcontroller31.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@ REQUEST_URI=/frontcontroller31.php
Content-type: text/html; charset=UTF-8
--FILE_EXTERNAL--
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', NULL, Array, Array)
#1 {main}
thrown in %s on line %d
--EXPECT--
TypeError: Phar::webPhar(): Argument #5 ($rewrite) must be a valid callback or null, class "fail" not found
Loading
Loading