Skip to content

Commit 3eb1029

Browse files
committed
Migrate resource returned by proc_open() to opaque object
1 parent dda6b8f commit 3eb1029

24 files changed

+278
-147
lines changed

Zend/Optimizer/zend_func_infos.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ static const func_info_t func_infos[] = {
643643
F1("password_get_info", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_ARRAY_OF_NULL),
644644
F1("password_hash", MAY_BE_STRING),
645645
#if defined(PHP_CAN_SUPPORT_PROC_OPEN)
646-
F1("proc_open", MAY_BE_RESOURCE|MAY_BE_FALSE),
646+
F1("proc_open", MAY_BE_OBJECT|MAY_BE_FALSE),
647647
#endif
648648
#if defined(PHP_CAN_SUPPORT_PROC_OPEN)
649649
F1("proc_get_status", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING),

ext/posix/tests/posix_ttyname_error_wrongparams.phpt

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ standard
1515

1616
var_dump(posix_ttyname(0)); // param not a resource
1717

18-
$descriptors = [["pty"], ["pty"], ["pty"], ["pipe", "w"]];
19-
$pipes = [];
20-
$process = proc_open('echo "foo";', $descriptors, $pipes);
18+
$bucket = stream_bucket_new(fopen('php://temp', 'w+'), '');
2119

2220
try {
23-
var_dump(posix_ttyname($process)); // wrong resource type
21+
var_dump(posix_ttyname($bucket->bucket)); // wrong resource type
2422
} catch (TypeError $e) {
2523
echo $e->getMessage(), "\n";
2624
}

ext/readline/tests/bug77812-libedit.phpt

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ fclose($pipes[0]);
2323
proc_close($proc);
2424
?>
2525
--EXPECTF--
26-
resource(%d) of type (process)
26+
object(Process)#1 (0) {
27+
}
2728
Interactive shell
2829

2930
bar

ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ $standard = new ReflectionExtension('standard');
88
var_dump($standard->getClassNames());
99
?>
1010
--EXPECT--
11-
array(4) {
11+
array(5) {
1212
[0]=>
1313
string(22) "__PHP_Incomplete_Class"
1414
[1]=>
1515
string(14) "AssertionError"
1616
[2]=>
17-
string(15) "php_user_filter"
17+
string(7) "Process"
1818
[3]=>
19+
string(15) "php_user_filter"
20+
[4]=>
1921
string(9) "Directory"
2022
}

ext/standard/basic_functions.c

+5
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */
303303

304304
assertion_error_ce = register_class_AssertionError(zend_ce_error);
305305

306+
#ifdef PHP_CAN_SUPPORT_PROC_OPEN
307+
process_ce = register_class_Process();
308+
php_register_process_class_handlers();
309+
#endif
310+
306311
BASIC_MINIT_SUBMODULE(var)
307312
BASIC_MINIT_SUBMODULE(file)
308313
BASIC_MINIT_SUBMODULE(pack)

ext/standard/basic_functions.h

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
extern zend_module_entry basic_functions_module;
3838
#define basic_functions_module_ptr &basic_functions_module
3939

40+
#ifdef PHP_CAN_SUPPORT_PROC_OPEN
41+
extern zend_class_entry *process_ce;
42+
extern void php_register_process_class_handlers(void);
43+
#endif
44+
4045
PHP_MINIT_FUNCTION(basic);
4146
PHP_MSHUTDOWN_FUNCTION(basic);
4247
PHP_RINIT_FUNCTION(basic);

ext/standard/basic_functions.stub.php

+14-8
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,16 @@ class AssertionError extends Error
15031503
{
15041504
}
15051505

1506+
#ifdef PHP_CAN_SUPPORT_PROC_OPEN
1507+
/**
1508+
* @strict-properties
1509+
* @not-serializable
1510+
*/
1511+
final class Process
1512+
{
1513+
}
1514+
#endif
1515+
15061516
/* main/main.c */
15071517

15081518
function set_time_limit(int $seconds): bool {}
@@ -3273,23 +3283,19 @@ function password_algos(): array {}
32733283
#ifdef PHP_CAN_SUPPORT_PROC_OPEN
32743284
/**
32753285
* @param array $pipes
3276-
* @return resource|false
32773286
* @refcount 1
32783287
*/
3279-
function proc_open(array|string $command, array $descriptor_spec, &$pipes, ?string $cwd = null, ?array $env_vars = null, ?array $options = null) {}
3288+
function proc_open(array|string $command, array $descriptor_spec, &$pipes, ?string $cwd = null, ?array $env_vars = null, ?array $options = null): Process|false {}
32803289

3281-
/** @param resource $process */
3282-
function proc_close($process): int {}
3290+
function proc_close(Process $process): int {}
32833291

3284-
/** @param resource $process */
3285-
function proc_terminate($process, int $signal = 15): bool {}
3292+
function proc_terminate(Process $process, int $signal = 15): bool {}
32863293

32873294
/**
3288-
* @param resource $process
32893295
* @return array<string, bool|int|string>
32903296
* @refcount 1
32913297
*/
3292-
function proc_get_status($process): array {}
3298+
function proc_get_status(Process $process): array {}
32933299
#endif
32943300

32953301
/* quot_print.c */

ext/standard/basic_functions_arginfo.h

+25-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)