Skip to content

Commit f3cdc8a

Browse files
committed
Test fixes
1 parent 18a1db2 commit f3cdc8a

11 files changed

+108
-9
lines changed

Zend/zend_closures.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ static zend_result zend_create_closure_from_callable(zval *return_value, zval *c
365365
call.handler = zend_closure_call_magic;
366366
call.function_name = mptr->common.function_name;
367367
call.scope = mptr->common.scope;
368+
call.doc_comment = NULL;
368369

369370
zend_free_trampoline(mptr);
370371
mptr = (zend_function *) &call;

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,12 @@ typedef struct _zend_internal_function {
520520
uint32_t num_args;
521521
uint32_t required_num_args;
522522
zend_internal_arg_info *arg_info;
523-
zend_string *doc_comment;
524523
HashTable *attributes;
525524
ZEND_MAP_PTR_DEF(void **, run_time_cache);
526525
uint32_t T; /* number of temporary variables */
527526
/* END of common elements */
528527

528+
zend_string *doc_comment;
529529
zif_handler handler;
530530
struct _zend_module_entry *module;
531531
const zend_frameless_function_info *frameless_function_infos;

Zend/zend_enum.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ void zend_enum_register_funcs(zend_class_entry *ce)
437437
cases_function->handler = zend_enum_cases_func;
438438
cases_function->function_name = ZSTR_KNOWN(ZEND_STR_CASES);
439439
cases_function->fn_flags = fn_flags;
440+
cases_function->doc_comment = NULL;
440441
cases_function->arg_info = (zend_internal_arg_info *) (arginfo_class_UnitEnum_cases + 1);
441442
zend_enum_register_func(ce, ZEND_STR_CASES, cases_function);
442443

@@ -445,6 +446,7 @@ void zend_enum_register_funcs(zend_class_entry *ce)
445446
from_function->handler = zend_enum_from_func;
446447
from_function->function_name = ZSTR_KNOWN(ZEND_STR_FROM);
447448
from_function->fn_flags = fn_flags;
449+
from_function->doc_comment = NULL;
448450
from_function->num_args = 1;
449451
from_function->required_num_args = 1;
450452
from_function->arg_info = (zend_internal_arg_info *) (arginfo_class_BackedEnum_from + 1);
@@ -454,6 +456,7 @@ void zend_enum_register_funcs(zend_class_entry *ce)
454456
try_from_function->handler = zend_enum_try_from_func;
455457
try_from_function->function_name = ZSTR_KNOWN(ZEND_STR_TRYFROM);
456458
try_from_function->fn_flags = fn_flags;
459+
try_from_function->doc_comment = NULL;
457460
try_from_function->num_args = 1;
458461
try_from_function->required_num_args = 1;
459462
try_from_function->arg_info = (zend_internal_arg_info *) (arginfo_class_BackedEnum_tryFrom + 1);

Zend/zend_execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ ZEND_API const zend_internal_function zend_pass_function = {
147147
0, /* num_args */
148148
0, /* required_num_args */
149149
(zend_internal_arg_info *) zend_pass_function_arg_info + 1, /* arg_info */
150-
NULL, /* doc_comment */
151150
NULL, /* attributes */
152151
NULL, /* run_time_cache */
153152
0, /* T */
153+
NULL, /* doc_comment */
154154
ZEND_FN(pass), /* handler */
155155
NULL, /* module */
156156
NULL, /* frameless_function_infos */

build/gen_stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,7 @@ private function getClassConstDeclaration(EvaluatedValue $value, array $allConst
26842684
$commentCode = "const_{$constName}_comment";
26852685
$escapedComment = $this->exposedDocComment->escape();
26862686
$escapedCommentLength = $this->exposedDocComment->getLength();
2687-
$code .= "\tzend_string *$commentCode = zend_string_init(\"$escapedComment\", $escapedCommentLength, 1);\n";
2687+
$code .= "\tzend_string *$commentCode = zend_string_init_interned(\"$escapedComment\", $escapedCommentLength, 1);\n";
26882688
} else {
26892689
$commentCode = "NULL";
26902690
}
@@ -2904,7 +2904,7 @@ public function getDeclaration(array $allConstInfos): string {
29042904
$commentCode = "property_{$propertyName}_comment";
29052905
$escapedComment = $this->exposedDocComment->escape();
29062906
$escapedCommentLength = $this->exposedDocComment->getLength();
2907-
$code .= "\tzend_string *$commentCode = zend_string_init(\"$escapedComment\", $escapedCommentLength, 1);\n";
2907+
$code .= "\tzend_string *$commentCode = zend_string_init_interned(\"$escapedComment\", $escapedCommentLength, 1);\n";
29082908
} else {
29092909
$commentCode = "NULL";
29102910
}
@@ -3176,7 +3176,7 @@ public function getRegistration(array $allConstInfos): string
31763176
$code .= "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n";
31773177
}
31783178

3179-
$code .= "\tclass_entry->doc_comment = zend_string_init(\"" . $this->exposedDocComment->escape() . "\", " . $this->exposedDocComment->getLength() . ", 1);\n";
3179+
$code .= "\tclass_entry->doc_comment = zend_string_init_interned(\"" . $this->exposedDocComment->escape() . "\", " . $this->exposedDocComment->getLength() . ", 1);\n";
31803180

31813181
if (!$php84MinimumCompatibility) {
31823182
$code .= "#endif\n";

ext/ffi/ffi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,7 @@ static zend_result zend_ffi_cdata_get_closure(zend_object *obj, zend_class_entry
21752175
func->common.arg_info = NULL;
21762176
func->internal_function.handler = ZEND_FN(ffi_trampoline);
21772177
func->internal_function.module = NULL;
2178+
func->internal_function.doc_comment = NULL;
21782179

21792180
func->internal_function.reserved[0] = type;
21802181
func->internal_function.reserved[1] = *(void**)cdata->ptr;
@@ -2927,6 +2928,7 @@ static zend_function *zend_ffi_get_func(zend_object **obj, zend_string *name, co
29272928
func->common.arg_info = NULL;
29282929
func->internal_function.handler = ZEND_FN(ffi_trampoline);
29292930
func->internal_function.module = NULL;
2931+
func->internal_function.doc_comment = NULL;
29302932

29312933
func->internal_function.reserved[0] = type;
29322934
func->internal_function.reserved[1] = sym->addr;

ext/reflection/php_reflection.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ static void _class_const_string(smart_str *str, zend_string *name, zend_class_co
566566
const char *final = ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_FINAL ? "final " : "";
567567
zend_string *type_str = ZEND_TYPE_IS_SET(c->type) ? zend_type_to_string(c->type) : NULL;
568568
const char *type = type_str ? ZSTR_VAL(type_str) : zend_zval_type_name(&c->value);
569+
570+
if (c->doc_comment) {
571+
smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(c->doc_comment));
572+
}
569573
smart_str_append_printf(str, "%sConstant [ %s%s %s %s ] { ",
570574
indent, final, visibility, type, ZSTR_VAL(name));
571575
if (Z_TYPE(c->value) == IS_ARRAY) {
@@ -780,6 +784,8 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
780784
*/
781785
if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
782786
smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(fptr->op_array.doc_comment));
787+
} else if (fptr->type == ZEND_INTERNAL_FUNCTION && fptr->internal_function.doc_comment) {
788+
smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(fptr->internal_function.doc_comment));
783789
}
784790

785791
smart_str_appendl(str, indent, strlen(indent));
@@ -889,6 +895,9 @@ static zval *property_get_default(zend_property_info *prop_info) {
889895
/* {{{ _property_string */
890896
static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent)
891897
{
898+
if (prop->doc_comment) {
899+
smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(prop->doc_comment));
900+
}
892901
smart_str_append_printf(str, "%sProperty [ ", indent);
893902
if (!prop) {
894903
smart_str_append_printf(str, "<dynamic> public $%s", prop_name);

ext/zend_test/test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ static zend_function *zend_test_class_method_get(zend_object **object, zend_stri
763763
fptr->scope = (*object)->ce;
764764
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
765765
fptr->function_name = zend_string_copy(name);
766-
fptr->handler = ZEND_FN(zend_test_func);
766+
fptr->handler = ZEND_FN(zend_test_func);
767+
fptr->doc_comment = NULL;
767768

768769
return (zend_function*)fptr;
769770
}
@@ -787,6 +788,7 @@ static zend_function *zend_test_class_static_method_get(zend_class_entry *ce, ze
787788
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER|ZEND_ACC_STATIC;
788789
fptr->function_name = zend_string_copy(name);
789790
fptr->handler = ZEND_FN(zend_test_func);
791+
fptr->doc_comment = NULL;
790792

791793
return (zend_function*)fptr;
792794
}

ext/zend_test/test_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ static zend_class_entry *register_class__ZendTestInterface(void)
785785
zval const_DUMMY_value;
786786
ZVAL_LONG(&const_DUMMY_value, 0);
787787
zend_string *const_DUMMY_name = zend_string_init_interned("DUMMY", sizeof("DUMMY") - 1, 1);
788-
zend_string *const_DUMMY_comment = zend_string_init("/**\n * \"Lorem ipsum\"\n * @see https://www.php.net\n * @since 8.2\n */", 98, 1);
788+
zend_string *const_DUMMY_comment = zend_string_init_interned("/**\n * \"Lorem ipsum\"\n * @see https://www.php.net\n * @since 8.2\n */", 98, 1);
789789
zend_declare_class_constant_ex(class_entry, const_DUMMY_name, &const_DUMMY_value, ZEND_ACC_PUBLIC, const_DUMMY_comment);
790790
zend_string_release(const_DUMMY_name);
791791

@@ -1062,13 +1062,13 @@ static zend_class_entry *register_class_ZendTestPropertyAttribute(void)
10621062
class_entry = zend_register_internal_class_ex(&ce, NULL);
10631063
class_entry->ce_flags |= ZEND_ACC_FINAL;
10641064
#if (PHP_VERSION_ID >= 80400)
1065-
class_entry->doc_comment = zend_string_init("/**\n * \"Lorem ipsum\"\n * @see https://www.php.net\n * @since 8.1\n */", 82, 1);
1065+
class_entry->doc_comment = zend_string_init_interned("/**\n * \"Lorem ipsum\"\n * @see https://www.php.net\n * @since 8.1\n */", 82, 1);
10661066
#endif
10671067

10681068
zval property_parameter_default_value;
10691069
ZVAL_UNDEF(&property_parameter_default_value);
10701070
zend_string *property_parameter_name = zend_string_init("parameter", sizeof("parameter") - 1, 1);
1071-
zend_string *property_parameter_comment = zend_string_init("/**\n * \"Lorem ipsum\"\n * @see https://www.php.net\n * @since 8.4\n */", 98, 1);
1071+
zend_string *property_parameter_comment = zend_string_init_interned("/**\n * \"Lorem ipsum\"\n * @see https://www.php.net\n * @since 8.4\n */", 98, 1);
10721072
zend_declare_typed_property(class_entry, property_parameter_name, &property_parameter_default_value, ZEND_ACC_PUBLIC, property_parameter_comment, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
10731073
zend_string_release(property_parameter_name);
10741074

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
--TEST--
2+
Test that displaying doc comments via reflection is supported by internal symbols
3+
--EXTENSIONS--
4+
zend_test
5+
reflection
6+
--FILE--
7+
<?php
8+
9+
$rc = new ReflectionClass(ZendTestPropertyAttribute::class);
10+
echo $rc->__toString() . "\n";
11+
12+
$rc = new ReflectionClassConstant(_ZendTestInterface::class, "DUMMY");
13+
echo $rc->__toString() . "\n";
14+
15+
$rf = new ReflectionFunction("zend_test_nullable_array_return");
16+
echo $rf->__toString() . "\n";
17+
18+
$rp = new ReflectionProperty(new ZendTestPropertyAttribute(""), "parameter");
19+
echo $rp->__toString() . "\n";
20+
21+
?>
22+
--EXPECT--
23+
/**
24+
* "Lorem ipsum"
25+
* @see https://www.php.net
26+
* @since 8.1
27+
*/
28+
Class [ <internal:zend_test> final class ZendTestPropertyAttribute ] {
29+
30+
- Constants [0] {
31+
}
32+
33+
- Static properties [0] {
34+
}
35+
36+
- Static methods [0] {
37+
}
38+
39+
- Properties [1] {
40+
/**
41+
* "Lorem ipsum"
42+
* @see https://www.php.net
43+
* @since 8.4
44+
*/
45+
Property [ public string $parameter ]
46+
}
47+
48+
- Methods [1] {
49+
Method [ <internal:zend_test, ctor> public method __construct ] {
50+
51+
- Parameters [1] {
52+
Parameter #0 [ <required> string $parameter ]
53+
}
54+
}
55+
}
56+
}
57+
58+
/**
59+
* "Lorem ipsum"
60+
* @see https://www.php.net
61+
* @since 8.2
62+
*/
63+
Constant [ public int DUMMY ] { 0 }
64+
65+
/**
66+
* "Lorem ipsum"
67+
* @see https://www.php.net
68+
* @since 8.3
69+
*/
70+
Function [ <internal:zend_test> function zend_test_nullable_array_return ] {
71+
72+
- Parameters [0] {
73+
}
74+
- Return [ ?array ]
75+
}
76+
77+
/**
78+
* "Lorem ipsum"
79+
* @see https://www.php.net
80+
* @since 8.4
81+
*/
82+
Property [ public string $parameter ]

0 commit comments

Comments
 (0)