Skip to content

Commit 0cc4b26

Browse files
committed
Update ReflectionFiber
Removed is* methods available on Fiber and added getCallable.
1 parent c6ff710 commit 0cc4b26

File tree

5 files changed

+74
-107
lines changed

5 files changed

+74
-107
lines changed

ext/reflection/php_reflection.c

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6772,23 +6772,20 @@ ZEND_METHOD(ReflectionFiber, __construct)
67726772
}
67736773
/* }}} */
67746774

6775-
/* {{{ proto Fiber ReflectionFiber::getFiber() */
67766775
ZEND_METHOD(ReflectionFiber, getFiber)
67776776
{
67786777
ZEND_PARSE_PARAMETERS_NONE();
67796778

67806779
RETURN_OBJ_COPY(Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj));
67816780
}
6782-
/* }}} */
67836781

67846782
#define REFLECTION_CHECK_VALID_FIBER(fiber) do { \
67856783
if (fiber == NULL || fiber->status == ZEND_FIBER_STATUS_INIT || fiber->status & ZEND_FIBER_STATUS_FINISHED) { \
67866784
zend_throw_error(NULL, "Cannot fetch information from a fiber that has not been started or is terminated"); \
6787-
return; \
6785+
RETURN_THROWS(); \
67886786
} \
67896787
} while (0)
67906788

6791-
/* {{{ proto array ReflectionFiber::getTrace(int $options) */
67926789
ZEND_METHOD(ReflectionFiber, getTrace)
67936790
{
67946791
zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj);
@@ -6810,9 +6807,7 @@ ZEND_METHOD(ReflectionFiber, getTrace)
68106807

68116808
EG(current_execute_data) = execute_data; // Restore original execute data.
68126809
}
6813-
/* }}} */
68146810

6815-
/* {{{ proto int ReflectionFiber::getExecutingLine() */
68166811
ZEND_METHOD(ReflectionFiber, getExecutingLine)
68176812
{
68186813
zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj);
@@ -6830,9 +6825,7 @@ ZEND_METHOD(ReflectionFiber, getExecutingLine)
68306825

68316826
RETURN_LONG(prev_execute_data->opline->lineno);
68326827
}
6833-
/* }}} */
68346828

6835-
/* {{{ proto string ReflectionFiber::getExecutingFile() */
68366829
ZEND_METHOD(ReflectionFiber, getExecutingFile)
68376830
{
68386831
zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj);
@@ -6850,51 +6843,20 @@ ZEND_METHOD(ReflectionFiber, getExecutingFile)
68506843

68516844
RETURN_STR_COPY(prev_execute_data->func->op_array.filename);
68526845
}
6853-
/* }}} */
6854-
6855-
/* {{{ proto bool ReflectionFiber::isStarted() */
6856-
ZEND_METHOD(ReflectionFiber, isStarted)
6857-
{
6858-
zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj);
6859-
6860-
ZEND_PARSE_PARAMETERS_NONE();
6861-
6862-
RETURN_BOOL(fiber->status != ZEND_FIBER_STATUS_INIT);
6863-
}
6864-
/* }}} */
68656846

6866-
/* {{{ proto bool ReflectionFiber::isSuspended() */
6867-
ZEND_METHOD(ReflectionFiber, isSuspended)
6847+
ZEND_METHOD(ReflectionFiber, getCallable)
68686848
{
68696849
zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj);
68706850

68716851
ZEND_PARSE_PARAMETERS_NONE();
68726852

6873-
RETURN_BOOL(fiber->status == ZEND_FIBER_STATUS_SUSPENDED);
6874-
}
6875-
/* }}} */
6876-
6877-
/* {{{ proto bool ReflectionFiber::isRunning() */
6878-
ZEND_METHOD(ReflectionFiber, isRunning)
6879-
{
6880-
zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj);
6881-
6882-
ZEND_PARSE_PARAMETERS_NONE();
6883-
6884-
RETURN_BOOL(fiber->status == ZEND_FIBER_STATUS_RUNNING);
6885-
}
6886-
/* }}} */
6887-
6888-
/* {{{ proto bool ReflectionFiber::isTerminated() */
6889-
ZEND_METHOD(ReflectionFiber, isTerminated)
6890-
{
6891-
zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj);
6892-
6893-
ZEND_PARSE_PARAMETERS_NONE();
6853+
if (fiber == NULL || fiber->status & ZEND_FIBER_STATUS_FINISHED) {
6854+
zend_throw_error(NULL, "Cannot fetch the callable from a fiber that has terminated"); \
6855+
RETURN_THROWS();
6856+
}
68946857

6895-
RETURN_BOOL(fiber->status & ZEND_FIBER_STATUS_FINISHED);
6858+
RETURN_COPY(&fiber->fci.function_name);
68966859
}
6897-
/* }}} */
68986860

68996861
/* {{{ _reflection_write_property */
69006862
static zval *_reflection_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,7 @@ public function getExecutingFile(): string {}
731731

732732
public function getExecutingLine(): int {}
733733

734-
public function getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT): array {}
735-
736-
public function isStarted(): bool {}
737-
738-
public function isSuspended(): bool {}
734+
public function getCallable(): callable {}
739735

740-
public function isRunning(): bool {}
741-
742-
public function isTerminated(): bool {}
736+
public function getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT): array {}
743737
}

ext/reflection/php_reflection_arginfo.h

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 5d890da977c41b3e230d368e6beb37f08a3d1446 */
2+
* Stub hash: 388312e928b54992da6b7e0e0f15dec72d9290f1 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@@ -534,18 +534,13 @@ ZEND_END_ARG_INFO()
534534

535535
#define arginfo_class_ReflectionFiber_getExecutingLine arginfo_class_ReflectionAttribute_getTarget
536536

537+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFiber_getCallable, 0, 0, IS_CALLABLE, 0)
538+
ZEND_END_ARG_INFO()
539+
537540
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFiber_getTrace, 0, 0, IS_ARRAY, 0)
538541
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "DEBUG_BACKTRACE_PROVIDE_OBJECT")
539542
ZEND_END_ARG_INFO()
540543

541-
#define arginfo_class_ReflectionFiber_isStarted arginfo_class_ReflectionClass_isEnum
542-
543-
#define arginfo_class_ReflectionFiber_isSuspended arginfo_class_ReflectionClass_isEnum
544-
545-
#define arginfo_class_ReflectionFiber_isRunning arginfo_class_ReflectionClass_isEnum
546-
547-
#define arginfo_class_ReflectionFiber_isTerminated arginfo_class_ReflectionClass_isEnum
548-
549544

550545
ZEND_METHOD(Reflection, getModifierNames);
551546
ZEND_METHOD(ReflectionClass, __clone);
@@ -763,11 +758,8 @@ ZEND_METHOD(ReflectionFiber, __construct);
763758
ZEND_METHOD(ReflectionFiber, getFiber);
764759
ZEND_METHOD(ReflectionFiber, getExecutingFile);
765760
ZEND_METHOD(ReflectionFiber, getExecutingLine);
761+
ZEND_METHOD(ReflectionFiber, getCallable);
766762
ZEND_METHOD(ReflectionFiber, getTrace);
767-
ZEND_METHOD(ReflectionFiber, isStarted);
768-
ZEND_METHOD(ReflectionFiber, isSuspended);
769-
ZEND_METHOD(ReflectionFiber, isRunning);
770-
ZEND_METHOD(ReflectionFiber, isTerminated);
771763

772764

773765
static const zend_function_entry class_ReflectionException_methods[] = {
@@ -1107,11 +1099,8 @@ static const zend_function_entry class_ReflectionFiber_methods[] = {
11071099
ZEND_ME(ReflectionFiber, getFiber, arginfo_class_ReflectionFiber_getFiber, ZEND_ACC_PUBLIC)
11081100
ZEND_ME(ReflectionFiber, getExecutingFile, arginfo_class_ReflectionFiber_getExecutingFile, ZEND_ACC_PUBLIC)
11091101
ZEND_ME(ReflectionFiber, getExecutingLine, arginfo_class_ReflectionFiber_getExecutingLine, ZEND_ACC_PUBLIC)
1102+
ZEND_ME(ReflectionFiber, getCallable, arginfo_class_ReflectionFiber_getCallable, ZEND_ACC_PUBLIC)
11101103
ZEND_ME(ReflectionFiber, getTrace, arginfo_class_ReflectionFiber_getTrace, ZEND_ACC_PUBLIC)
1111-
ZEND_ME(ReflectionFiber, isStarted, arginfo_class_ReflectionFiber_isStarted, ZEND_ACC_PUBLIC)
1112-
ZEND_ME(ReflectionFiber, isSuspended, arginfo_class_ReflectionFiber_isSuspended, ZEND_ACC_PUBLIC)
1113-
ZEND_ME(ReflectionFiber, isRunning, arginfo_class_ReflectionFiber_isRunning, ZEND_ACC_PUBLIC)
1114-
ZEND_ME(ReflectionFiber, isTerminated, arginfo_class_ReflectionFiber_isTerminated, ZEND_ACC_PUBLIC)
11151104
ZEND_FE_END
11161105
};
11171106

ext/reflection/tests/ReflectionFiber_basic.phpt

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,86 @@ ReflectionFiber basic tests
33
--FILE--
44
<?php
55

6-
$fiber = new Fiber(function (): void {
7-
$fiber = Fiber::this();
6+
$callable = function (): void {
7+
$reflection = new ReflectionFiber(Fiber::this());
88
echo "\nWithin Fiber:\n";
9-
var_dump($fiber->isStarted());
10-
var_dump($fiber->isRunning());
11-
var_dump($fiber->isSuspended());
12-
var_dump($fiber->isTerminated());
9+
var_dump($reflection->getExecutingFile());
10+
var_dump($reflection->getExecutingLine());
11+
var_dump($reflection->getTrace());
1312
Fiber::suspend();
14-
});
13+
};
14+
15+
$fiber = new Fiber($callable);
1516

1617
$reflection = new ReflectionFiber($fiber);
1718

1819
echo "Before Start:\n";
1920
var_dump($fiber === $reflection->getFiber());
20-
var_dump($reflection->isStarted());
21-
var_dump($reflection->isRunning());
22-
var_dump($reflection->isSuspended());
23-
var_dump($reflection->isTerminated());
21+
var_dump($callable === $reflection->getCallable());
2422

2523
$fiber->start();
2624

2725
echo "\nAfter Start:\n";
28-
var_dump($reflection->isStarted());
29-
var_dump($reflection->isRunning());
30-
var_dump($reflection->isSuspended());
31-
var_dump($reflection->isTerminated());
3226
var_dump($reflection->getExecutingFile());
3327
var_dump($reflection->getExecutingLine());
28+
var_dump($callable === $reflection->getCallable());
3429
var_dump($reflection->getTrace());
3530

3631
$fiber->resume();
3732

3833
echo "\nAfter Resume:\n";
39-
var_dump($fiber->isStarted());
40-
var_dump($fiber->isRunning());
41-
var_dump($fiber->isSuspended());
42-
var_dump($fiber->isTerminated());
34+
$reflection->getTrace();
4335

4436
?>
4537
--EXPECTF--
4638
Before Start:
4739
bool(true)
48-
bool(false)
49-
bool(false)
50-
bool(false)
51-
bool(false)
40+
bool(true)
5241

5342
Within Fiber:
54-
bool(true)
55-
bool(true)
56-
bool(false)
57-
bool(false)
43+
string(%d) "%sReflectionFiber_basic.php"
44+
int(7)
45+
array(2) {
46+
[0]=>
47+
array(7) {
48+
["file"]=>
49+
string(%d) "%sReflectionFiber_basic.php"
50+
["line"]=>
51+
int(8)
52+
["function"]=>
53+
string(8) "getTrace"
54+
["class"]=>
55+
string(15) "ReflectionFiber"
56+
["object"]=>
57+
object(ReflectionFiber)#4 (0) {
58+
}
59+
["type"]=>
60+
string(2) "->"
61+
["args"]=>
62+
array(0) {
63+
}
64+
}
65+
[1]=>
66+
array(2) {
67+
["function"]=>
68+
string(9) "{closure}"
69+
["args"]=>
70+
array(0) {
71+
}
72+
}
73+
}
5874

5975
After Start:
60-
bool(true)
61-
bool(false)
62-
bool(true)
63-
bool(false)
6476
string(%d) "%sReflectionFiber_basic.php"
65-
int(10)
77+
int(9)
78+
bool(true)
6679
array(2) {
6780
[0]=>
6881
array(6) {
6982
["file"]=>
7083
string(%d) "%sReflectionFiber_basic.php"
7184
["line"]=>
72-
int(10)
85+
int(9)
7386
["function"]=>
7487
string(7) "suspend"
7588
["class"]=>
@@ -91,7 +104,9 @@ array(2) {
91104
}
92105

93106
After Resume:
94-
bool(true)
95-
bool(false)
96-
bool(false)
97-
bool(true)
107+
108+
Fatal error: Uncaught Error: Cannot fetch information from a fiber that has not been started or is terminated in %sReflectionFiber_basic.php:%d
109+
Stack trace:
110+
#0 %sReflectionFiber_basic.php(%d): ReflectionFiber->getTrace()
111+
#1 {main}
112+
thrown in %sReflectionFiber_basic.php on line %d

ext/reflection/tests/ReflectionFiber_errors.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ try {
5252
echo $error->getMessage(), "\n";
5353
}
5454

55+
try {
56+
$reflection->getCallable();
57+
} catch (Error $error) {
58+
echo $error->getMessage(), "\n";
59+
}
60+
5561
?>
5662
--EXPECTF--
5763
Cannot fetch information from a fiber that has not been started or is terminated
@@ -62,3 +68,4 @@ int(4)
6268
Cannot fetch information from a fiber that has not been started or is terminated
6369
Cannot fetch information from a fiber that has not been started or is terminated
6470
Cannot fetch information from a fiber that has not been started or is terminated
71+
Cannot fetch the callable from a fiber that has terminated

0 commit comments

Comments
 (0)