Skip to content

Commit ffb730a

Browse files
committed
Display the default values of parameters of internal functions correctly
1 parent 86c33b8 commit ffb730a

File tree

7 files changed

+94
-46
lines changed

7 files changed

+94
-46
lines changed

Zend/tests/closures/closure_from_callable_basic.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $foo = new SubFoo;
8181
$fn = $foo->getSelfColonParentPublicInstanceMethod();
8282
echo $fn(" OK".PHP_EOL);
8383

84-
echo 'Access proteced instance method of parent object through "self::" to parent method';
84+
echo 'Access protected instance method of parent object through "self::" to parent method';
8585
$foo = new SubFoo;
8686
$fn = $foo->getSelfColonParentProtectedInstanceMethod();
8787
echo $fn(" OK".PHP_EOL);
@@ -115,7 +115,7 @@ Subclass closure over parent class static protected method OK
115115
Access public instance method of parent object through "parent::" OK
116116
Access public instance method of self object through "self::" OK
117117
Access public instance method of parent object through "self::" to parent method OK
118-
Access proteced instance method of parent object through "self::" to parent method OK
118+
Access protected instance method of parent object through "self::" to parent method OK
119119
MagicCall __call instance method __call,nonExistentMethod, OK
120120
MagicCall __callStatic static method __callStatic,nonExistentMethod, OK
121121
===DONE===
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Default value
3+
--FILE--
4+
<?php
5+
6+
class MyDateTime extends DateTime
7+
{
8+
public function setTime(int $hour, int $minute, int $second = 0, bool $microseconds = false)
9+
{
10+
}
11+
}
12+
echo "OK";
13+
--EXPECTF--
14+
Fatal error: Declaration of MyDateTime::setTime(int $hour, int $minute, int $second = 0, bool $microseconds = false) must be compatible with DateTime::setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0) in %s on line %d

Zend/zend_API.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,33 @@ typedef struct _zend_fcall_info_cache {
9696

9797
#define ZEND_FE_END { NULL, NULL, NULL, 0, 0 }
9898

99-
#define ZEND_ARG_INFO(pass_by_ref, name) { #name, 0, pass_by_ref, 0},
100-
#define ZEND_ARG_PASS_INFO(pass_by_ref) { NULL, 0, pass_by_ref, 0},
101-
#define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), pass_by_ref, 0 },
102-
#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(IS_ARRAY, allow_null), pass_by_ref, 0 },
103-
#define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(IS_CALLABLE, allow_null), pass_by_ref, 0 },
104-
#define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(type_hint, allow_null), pass_by_ref, 0 },
105-
#define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name) { #name, 0, pass_by_ref, 1 },
106-
#define ZEND_ARG_VARIADIC_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(type_hint, allow_null), pass_by_ref, 1 },
107-
#define ZEND_ARG_VARIADIC_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), pass_by_ref, 1 },
99+
#define ZEND_ARG_INFO(pass_by_ref, name) { #name, 0, pass_by_ref, NULL, 0},
100+
#define ZEND_ARG_PASS_INFO(pass_by_ref) { NULL, 0, pass_by_ref, NULL, 0},
101+
#define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), pass_by_ref, NULL, 0 },
102+
#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(IS_ARRAY, allow_null), pass_by_ref, NULL, 0 },
103+
#define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(IS_CALLABLE, allow_null), pass_by_ref, NULL, 0 },
104+
#define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(type_hint, allow_null), pass_by_ref, NULL, 0 },
105+
#define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value) { #name, ZEND_TYPE_ENCODE_CODE(type_hint, allow_null), pass_by_ref, default_value, 0 },
106+
#define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name) { #name, 0, pass_by_ref, NULL, 1 },
107+
#define ZEND_ARG_VARIADIC_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, ZEND_TYPE_ENCODE_CODE(type_hint, allow_null), pass_by_ref, NULL, 1 },
108+
#define ZEND_ARG_VARIADIC_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), pass_by_ref, NULL, 1 },
108109

109110
#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
110111
static const zend_internal_arg_info name[] = { \
111-
{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#class_name, allow_null), return_reference, 0 },
112+
{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#class_name, allow_null), return_reference, NULL, 0 },
112113

113114
#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
114115
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, 0, -1, class_name, allow_null)
115116

116117
#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
117118
static const zend_internal_arg_info name[] = { \
118-
{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CODE(type, allow_null), return_reference, 0 },
119+
{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CODE(type, allow_null), return_reference, NULL, 0},
119120
#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
120121
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, type, allow_null)
121122

122123
#define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args) \
123124
static const zend_internal_arg_info name[] = { \
124-
{ (const char*)(zend_uintptr_t)(required_num_args), 0, return_reference, 0 },
125+
{ (const char*)(zend_uintptr_t)(required_num_args), 0, return_reference, NULL, 0 },
125126
#define ZEND_BEGIN_ARG_INFO(name, _unused) \
126127
ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1)
127128
#define ZEND_END_ARG_INFO() };

Zend/zend_compile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ typedef struct _zend_internal_arg_info {
384384
const char *name;
385385
zend_type type;
386386
zend_uchar pass_by_reference;
387+
const char *default_value;
387388
zend_bool is_variadic;
388389
} zend_internal_arg_info;
389390

@@ -392,6 +393,7 @@ typedef struct _zend_arg_info {
392393
zend_string *name;
393394
zend_type type;
394395
zend_uchar pass_by_reference;
396+
const char *default_value;
395397
zend_bool is_variadic;
396398
} zend_arg_info;
397399

@@ -404,6 +406,7 @@ typedef struct _zend_internal_function_info {
404406
zend_uintptr_t required_num_args;
405407
zend_type type;
406408
zend_bool return_reference;
409+
const char *default_value;
407410
zend_bool _is_variadic;
408411
} zend_internal_function_info;
409412

Zend/zend_inheritance.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,12 @@ static ZEND_COLD zend_string *zend_get_function_declaration(const zend_function
621621
}
622622
}
623623
} else {
624-
smart_str_appends(&str, "NULL");
624+
zend_internal_arg_info *internal_arginfo = (zend_internal_arg_info*) arg_info;
625+
if (internal_arginfo->default_value != NULL) {
626+
smart_str_appends(&str, internal_arginfo->default_value);
627+
} else {
628+
smart_str_appends(&str, "<default>");
629+
}
625630
}
626631
}
627632

ext/date/php_date_arginfo.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ ZEND_END_ARG_INFO()
4343

4444
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_localtime, 0, 0, IS_ARRAY, 0)
4545
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
46-
ZEND_ARG_TYPE_INFO(0, associative, _IS_BOOL, 0)
46+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, associative, _IS_BOOL, 0, "false")
4747
ZEND_END_ARG_INFO()
4848

4949
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getdate, 0, 0, IS_ARRAY, 0)
5050
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
5151
ZEND_END_ARG_INFO()
5252

5353
ZEND_BEGIN_ARG_INFO_EX(arginfo_date_create, 0, 0, 0)
54-
ZEND_ARG_TYPE_INFO(0, time, IS_STRING, 0)
54+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, time, IS_STRING, 0, "\"now\"")
5555
ZEND_ARG_OBJ_INFO(0, timezone, DateTimeZone, 1)
5656
ZEND_END_ARG_INFO()
5757

@@ -110,15 +110,15 @@ ZEND_END_ARG_INFO()
110110
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_diff, 0, 2, DateInterval, 0)
111111
ZEND_ARG_OBJ_INFO(0, object, DateTimeInterface, 0)
112112
ZEND_ARG_OBJ_INFO(0, object2, DateTimeInterface, 0)
113-
ZEND_ARG_TYPE_INFO(0, absolute, _IS_BOOL, 0)
113+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, absolute, _IS_BOOL, 0, "false")
114114
ZEND_END_ARG_INFO()
115115

116116
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_time_set, 0, 3, DateTime, 0)
117117
ZEND_ARG_OBJ_INFO(0, object, DateTime, 0)
118118
ZEND_ARG_TYPE_INFO(0, hour, IS_LONG, 0)
119119
ZEND_ARG_TYPE_INFO(0, minute, IS_LONG, 0)
120-
ZEND_ARG_TYPE_INFO(0, second, IS_LONG, 0)
121-
ZEND_ARG_TYPE_INFO(0, microseconds, IS_LONG, 0)
120+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, second, IS_LONG, 0, "0")
121+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, microseconds, IS_LONG, 0, "0")
122122
ZEND_END_ARG_INFO()
123123

124124
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_date_set, 0, 4, DateTime, 0)
@@ -132,7 +132,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_isodate_set, 0, 3, DateTime,
132132
ZEND_ARG_OBJ_INFO(0, object, DateTime, 0)
133133
ZEND_ARG_TYPE_INFO(0, year, IS_LONG, 0)
134134
ZEND_ARG_TYPE_INFO(0, week, IS_LONG, 0)
135-
ZEND_ARG_TYPE_INFO(0, day, IS_LONG, 0)
135+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, day, IS_LONG, 0, "1")
136136
ZEND_END_ARG_INFO()
137137

138138
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_timestamp_set, 0, 2, DateTime, 0)
@@ -152,8 +152,8 @@ ZEND_END_ARG_INFO()
152152

153153
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_name_from_abbr, 0, 0, 1)
154154
ZEND_ARG_TYPE_INFO(0, abbr, IS_STRING, 0)
155-
ZEND_ARG_TYPE_INFO(0, gmtoffset, IS_LONG, 0)
156-
ZEND_ARG_TYPE_INFO(0, isdst, IS_LONG, 0)
155+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, gmtoffset, IS_LONG, 0, "-1")
156+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, isdst, IS_LONG, 0, "-1")
157157
ZEND_END_ARG_INFO()
158158

159159
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_timezone_offset_get, 0, 2, IS_LONG, 0)
@@ -163,17 +163,17 @@ ZEND_END_ARG_INFO()
163163

164164
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_transitions_get, 0, 0, 1)
165165
ZEND_ARG_OBJ_INFO(0, object, DateTimeZone, 0)
166-
ZEND_ARG_TYPE_INFO(0, timestamp_begin, IS_LONG, 0)
167-
ZEND_ARG_TYPE_INFO(0, timestamp_end, IS_LONG, 0)
166+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp_begin, IS_LONG, 0, "PHP_INT_MIN")
167+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp_end, IS_LONG, 0, "PHP_INT_MAX")
168168
ZEND_END_ARG_INFO()
169169

170170
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_location_get, 0, 0, 1)
171171
ZEND_ARG_OBJ_INFO(0, object, DateTimeZone, 0)
172172
ZEND_END_ARG_INFO()
173173

174174
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_identifiers_list, 0, 0, 0)
175-
ZEND_ARG_TYPE_INFO(0, what, IS_LONG, 0)
176-
ZEND_ARG_TYPE_INFO(0, country, IS_STRING, 1)
175+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, what, IS_LONG, 0, "DateTimeZone::ALL")
176+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, country, IS_STRING, 1, "null")
177177
ZEND_END_ARG_INFO()
178178

179179
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_timezone_abbreviations_list, 0, 0, IS_ARRAY, 0)
@@ -199,11 +199,11 @@ ZEND_END_ARG_INFO()
199199

200200
ZEND_BEGIN_ARG_INFO_EX(arginfo_date_sunrise, 0, 0, 1)
201201
ZEND_ARG_TYPE_INFO(0, time, IS_LONG, 0)
202-
ZEND_ARG_TYPE_INFO(0, retformat, IS_LONG, 0)
202+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retformat, IS_LONG, 0, "SUNFUNCS_RET_STRING")
203203
ZEND_ARG_TYPE_INFO(0, latitude, IS_DOUBLE, 0)
204204
ZEND_ARG_TYPE_INFO(0, longitude, IS_DOUBLE, 0)
205205
ZEND_ARG_TYPE_INFO(0, zenith, IS_DOUBLE, 0)
206-
ZEND_ARG_TYPE_INFO(0, gmt_offset, IS_DOUBLE, 0)
206+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, gmt_offset, IS_DOUBLE, 0, "0")
207207
ZEND_END_ARG_INFO()
208208

209209
#define arginfo_date_sunset arginfo_date_sunrise
@@ -226,7 +226,7 @@ ZEND_END_ARG_INFO()
226226

227227
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTimeInterface_diff, 0, 0, 1)
228228
ZEND_ARG_OBJ_INFO(0, object, DateTimeInterface, 0)
229-
ZEND_ARG_TYPE_INFO(0, absolute, _IS_BOOL, 0)
229+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, absolute, _IS_BOOL, 0, "false")
230230
ZEND_END_ARG_INFO()
231231

232232
#define arginfo_class_DateTimeInterface___wakeup arginfo_date_get_last_errors
@@ -262,8 +262,8 @@ ZEND_END_ARG_INFO()
262262
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTime_setTime, 0, 0, 2)
263263
ZEND_ARG_TYPE_INFO(0, hour, IS_LONG, 0)
264264
ZEND_ARG_TYPE_INFO(0, minute, IS_LONG, 0)
265-
ZEND_ARG_TYPE_INFO(0, second, IS_LONG, 0)
266-
ZEND_ARG_TYPE_INFO(0, microseconds, IS_LONG, 0)
265+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, second, IS_LONG, 0, "0")
266+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, microseconds, IS_LONG, 0, "0")
267267
ZEND_END_ARG_INFO()
268268

269269
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTime_setDate, 0, 0, 3)
@@ -275,7 +275,7 @@ ZEND_END_ARG_INFO()
275275
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTime_setISODate, 0, 0, 2)
276276
ZEND_ARG_TYPE_INFO(0, year, IS_LONG, 0)
277277
ZEND_ARG_TYPE_INFO(0, week, IS_LONG, 0)
278-
ZEND_ARG_TYPE_INFO(0, day, IS_LONG, 0)
278+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, day, IS_LONG, 0, "1")
279279
ZEND_END_ARG_INFO()
280280

281281
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTime_setTimestamp, 0, 0, 1)
@@ -315,8 +315,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTimeZone_getOffset, 0, 0, 1)
315315
ZEND_END_ARG_INFO()
316316

317317
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTimeZone_getTransitions, 0, 0, 0)
318-
ZEND_ARG_TYPE_INFO(0, timestamp_begin, IS_LONG, 0)
319-
ZEND_ARG_TYPE_INFO(0, timestamp_end, IS_LONG, 0)
318+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp_begin, IS_LONG, 0, "PHP_INT_MIN")
319+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp_end, IS_LONG, 0, "PHP_INT_MAX")
320320
ZEND_END_ARG_INFO()
321321

322322
#define arginfo_class_DateTimeZone_getLocation arginfo_date_get_last_errors

scripts/dev/gen_stub.php

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
use PhpParser\Node;
55
use PhpParser\Node\Expr;
6+
use PhpParser\Node\Name;
67
use PhpParser\Node\Stmt;
8+
use PhpParser\PrettyPrinter\Standard;
9+
use PhpParser\PrettyPrinterAbstract;
710

811
error_reporting(E_ALL);
912

@@ -14,6 +17,13 @@
1417
exit(1);
1518
}
1619

20+
class CustomPrettyPrinter extends Standard
21+
{
22+
protected function pName_FullyQualified(Name\FullyQualified $node) {
23+
return implode('\\', $node->parts);
24+
}
25+
}
26+
1727
if ($argc >= 2) {
1828
// Generate single file.
1929
processStubFile($argv[1]);
@@ -121,19 +131,23 @@ class ArgInfo {
121131
public $isVariadic;
122132
/** @var Type|null */
123133
public $type;
134+
/** @var string|null */
135+
public $defaultValue;
124136

125-
public function __construct(string $name, int $sendBy, bool $isVariadic, ?Type $type) {
137+
public function __construct(string $name, int $sendBy, bool $isVariadic, ?Type $type, ?string $defaultValue) {
126138
$this->name = $name;
127139
$this->sendBy = $sendBy;
128140
$this->isVariadic = $isVariadic;
129141
$this->type = $type;
142+
$this->defaultValue = $defaultValue;
130143
}
131144

132145
public function equals(ArgInfo $other): bool {
133146
return $this->name === $other->name
134147
&& $this->sendBy === $other->sendBy
135148
&& $this->isVariadic === $other->isVariadic
136-
&& Type::equals($this->type, $other->type);
149+
&& Type::equals($this->type, $other->type)
150+
&& $this->defaultValue === $other->defaultValue;
137151
}
138152

139153
public function getSendByString(): string {
@@ -205,7 +219,7 @@ public function equalsApartFromName(FuncInfo $other): bool {
205219
}
206220
}
207221

208-
function parseFunctionLike(string $name, Node\FunctionLike $func, ?string $cond): FuncInfo {
222+
function parseFunctionLike(PrettyPrinterAbstract $prettyPinter, string $name, Node\FunctionLike $func, ?string $cond): FuncInfo {
209223
$comment = $func->getDocComment();
210224
$paramMeta = [];
211225

@@ -257,7 +271,8 @@ function parseFunctionLike(string $name, Node\FunctionLike $func, ?string $cond)
257271
$varName,
258272
$sendBy,
259273
$param->variadic,
260-
$param->type ? Type::fromNode($param->type) : null
274+
$param->type ? Type::fromNode($param->type) : null,
275+
$param->default ? $prettyPinter->prettyPrintExpr($param->default) : null
261276
);
262277
if (!$param->default && !$param->variadic) {
263278
$numRequiredArgs = $i + 1;
@@ -315,6 +330,7 @@ function parseStubFile(string $fileName) {
315330
$parser = new PhpParser\Parser\Php7($lexer);
316331
$nodeTraverser = new PhpParser\NodeTraverser;
317332
$nodeTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
333+
$prettyPrinter = new CustomPrettyPrinter();
318334

319335
$stmts = $parser->parse($code);
320336
$nodeTraverser->traverse($stmts);
@@ -328,7 +344,7 @@ function parseStubFile(string $fileName) {
328344
}
329345

330346
if ($stmt instanceof Stmt\Function_) {
331-
$funcInfos[] = parseFunctionLike($stmt->name->toString(), $stmt, $cond);
347+
$funcInfos[] = parseFunctionLike($prettyPrinter, $stmt->name->toString(), $stmt, $cond);
332348
continue;
333349
}
334350

@@ -345,7 +361,7 @@ function parseStubFile(string $fileName) {
345361
}
346362

347363
$funcInfos[] = parseFunctionLike(
348-
'class_' . $className . '_' . $classStmt->name->toString(), $classStmt, $cond);
364+
$prettyPrinter, 'class_' . $className . '_' . $classStmt->name->toString(), $classStmt, $cond);
349365
}
350366
continue;
351367
}
@@ -384,11 +400,20 @@ function funcInfoToCode(FuncInfo $funcInfo): string {
384400
$argKind = $argInfo->isVariadic ? "ARG_VARIADIC" : "ARG";
385401
if ($argInfo->type) {
386402
if ($argInfo->type->isBuiltin) {
387-
$code .= sprintf(
388-
"\tZEND_%s_TYPE_INFO(%s, %s, %s, %d)\n",
389-
$argKind, $argInfo->getSendByString(), $argInfo->name,
390-
$argInfo->type->toTypeCode(), $argInfo->type->isNullable
391-
);
403+
if ($argInfo->defaultValue === null || $argInfo->defaultValue === 'UNKNOWN') {
404+
$code .= sprintf(
405+
"\tZEND_%s_TYPE_INFO(%s, %s, %s, %d)\n",
406+
$argKind, $argInfo->getSendByString(), $argInfo->name,
407+
$argInfo->type->toTypeCode(), $argInfo->type->isNullable
408+
);
409+
} else {
410+
$code .= sprintf(
411+
"\tZEND_%s_TYPE_INFO_WITH_DEFAULT_VALUE(%s, %s, %s, %d, \"%s\")\n",
412+
$argKind, $argInfo->getSendByString(), $argInfo->name,
413+
$argInfo->type->toTypeCode(), $argInfo->type->isNullable,
414+
addslashes($argInfo->defaultValue)
415+
);
416+
}
392417
} else {
393418
$code .= sprintf(
394419
"\tZEND_%s_OBJ_INFO(%s, %s, %s, %d)\n",

0 commit comments

Comments
 (0)