Skip to content

Commit 0c2d4d6

Browse files
committed
Make sure that params with null default are marked nullable
1 parent a47f170 commit 0c2d4d6

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

ext/readline/readline.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/** @return string|false */
4-
function readline(string $prompt = null) {}
4+
function readline(?string $prompt = null) {}
55

66
/** @return mixed */
77
function readline_info(string $varname = UNKNOWN, string $newvalue = UNKNOWN) {}

ext/readline/readline_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This is a generated file, edit the .stub.php file instead. */
22

33
ZEND_BEGIN_ARG_INFO_EX(arginfo_readline, 0, 0, 0)
4-
ZEND_ARG_TYPE_INFO(0, prompt, IS_STRING, 0)
4+
ZEND_ARG_TYPE_INFO(0, prompt, IS_STRING, 1)
55
ZEND_END_ARG_INFO()
66

77
ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_info, 0, 0, 0)

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ function inet_pton (string $ip_address) {}
356356
function metaphone(string $text, int $phones = 0) {}
357357

358358
/* {{{ head.c */
359-
function header(string $string, bool $replace = true, int $http_response_code = null): void { }
359+
function header(string $string, bool $replace = true, int $http_response_code = 0): void { }
360360

361361
function header_remove(string $name = UNKNOWN): void { }
362362

scripts/dev/gen_stub.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<?php declare(strict_types=1);
33

44
use PhpParser\Node;
5+
use PhpParser\Node\Expr;
56
use PhpParser\Node\Stmt;
67

78
error_reporting(E_ALL);
@@ -38,7 +39,7 @@ function processStubFile(string $stubFile) {
3839
$arginfoCode = generateArgInfoCode($funcInfos);
3940
file_put_contents($arginfoFile, $arginfoCode);
4041
} catch (Exception $e) {
41-
echo "Caught {$e->getMessage()} while processing $stubFile\n";
42+
echo "In $stubFile:\n{$e->getMessage()}\n";
4243
exit(1);
4344
}
4445
}
@@ -230,6 +231,14 @@ function parseFunctionLike(string $name, Node\FunctionLike $func, ?string $cond)
230231
throw new Exception("Error in function $name: only the last parameter can be variadic");
231232
}
232233

234+
if ($param->default instanceof Expr\ConstFetch &&
235+
$param->default->name->toLowerString() === "null" &&
236+
$param->type && !($param->type instanceof Node\NullableType)
237+
) {
238+
throw new Exception(
239+
"Parameter $varName of function $name has null default, but is not nullable");
240+
}
241+
233242
$foundVariadic = $param->variadic;
234243

235244
$args[] = new ArgInfo(

0 commit comments

Comments
 (0)