Skip to content

Commit 840d665

Browse files
committed
Deprecate Phar::setStub(resource $stub, int $length)
1 parent 7ae0273 commit 840d665

7 files changed

+52
-5
lines changed

ext/phar/phar_object.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,6 +2871,13 @@ PHP_METHOD(Phar, setStub)
28712871
}
28722872

28732873
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "r|l", &zstub, &len) == SUCCESS) {
2874+
zend_string *method_name = get_active_function_or_method_name();
2875+
zend_error(E_DEPRECATED, "Calling %s(resource $stub, int $length) is deprecated", ZSTR_VAL(method_name));
2876+
zend_string_release(method_name);
2877+
if (UNEXPECTED(EG(exception))) {
2878+
RETURN_THROWS();
2879+
}
2880+
28742881
if ((php_stream_from_zval_no_verify(stream, zstub)) != NULL) {
28752882
if (len > 0) {
28762883
len = -len;

ext/phar/tests/cache_list/copyonwrite10.phar.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ phar.readonly=0
88
phar
99
--FILE_EXTERNAL--
1010
files/write10.phar
11-
--EXPECT--
11+
--EXPECTF--
1212
string(214) "<?php
1313
$p = new Phar(__FILE__);
1414
var_dump($p->getStub());
@@ -19,6 +19,8 @@ echo $p2->getStub(),"\n";
1919
echo "ok\n";
2020
__HALT_COMPILER(); ?>
2121
"
22+
23+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
2224
<?php __HALT_COMPILER(); ?>
2325

2426
ok

ext/phar/tests/phar_stub.phpt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ echo file_get_contents($fname2) . "\n";
5555
$fp = fopen($fname2, 'rb');
5656

5757
//// 4
58+
set_error_handler(function ($severity, $message, $file, $line) {
59+
throw new Exception($message);
60+
});
61+
try {
62+
$phar->setStub($fp);
63+
} catch (Exception $e) {
64+
echo $e->getMessage() . "\n";
65+
}
66+
set_error_handler(null);
67+
fclose($fp);
68+
69+
$fp = fopen($fname, 'rb');
70+
echo fread($fp, strlen($file)) . "\n";
71+
fclose($fp);
72+
73+
$fp = fopen($fname2, 'rb');
74+
75+
//// 5
5876
$phar->setStub($fp, strlen($file));
5977
fclose($fp);
6078

@@ -81,10 +99,16 @@ unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
8199
unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
82100
__HALT_COMPILER();
83101
?>
84-
--EXPECT--
102+
--EXPECTF--
85103
<?php echo "first stub\n"; __HALT_COMPILER(); ?>
86104
<?php echo "second stub\n"; __HALT_COMPILER(); ?>
105+
106+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
87107
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
88108
<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
109+
Calling Phar::setStub(resource $stub, int $length) is deprecated
110+
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
111+
112+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
89113
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
90114
<?php echo "third stub\n"; __HALT_COMPILER(); ?>

ext/phar/tests/phar_stub_write_file.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ var_dump($phar->getStub() == $sexp);
4747
unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
4848
__HALT_COMPILER();
4949
?>
50-
--EXPECT--
50+
--EXPECTF--
5151
string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
5252
string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
5353
bool(true)
54+
55+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
5456
string(51) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>
5557
"
5658
bool(false)

ext/phar/tests/tar/phar_stub.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar.php');
6464
unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
6565
__HALT_COMPILER();
6666
?>
67-
--EXPECT--
67+
--EXPECTF--
6868
<?php echo "first stub\n"; __HALT_COMPILER(); ?>
6969
<?php echo "second stub\n"; __HALT_COMPILER(); ?>
70+
71+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
7072
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
7173
<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
74+
75+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
7276
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
7377
<?php echo "third stub\n"; __HALT_COMPILER(); ?>

ext/phar/tests/zip/phar_begin_setstub_commit.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ string(5) "Hello"
6060
string(5) "World"
6161
string(%d) "<?php var_dump("Second"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
6262
"
63+
64+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
6365
string(%d) "<?php var_dump("First resource"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
6466
"
67+
68+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
6569
string(%d) "<?php var_dump("First resource"); Phar::mapPhar("phar_begin_setstub_commit.phar"); __HALT_COMPILER(); ?>
6670
"

ext/phar/tests/zip/phar_stub.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php');
6464
unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
6565
__HALT_COMPILER();
6666
?>
67-
--EXPECT--
67+
--EXPECTF--
6868
<?php echo "first stub\n"; __HALT_COMPILER(); ?>
6969
<?php echo "second stub\n"; __HALT_COMPILER(); ?>
70+
71+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
7072
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
7173
<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
74+
75+
Deprecated: Calling Phar::setStub(resource $stub, int $length) is deprecated in %s on line %d
7276
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
7377
<?php echo "third stub\n"; __HALT_COMPILER(); ?>

0 commit comments

Comments
 (0)