]> granicus.if.org Git - php/commitdiff
Make sure that params with null default are marked nullable
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 26 Aug 2019 12:34:28 +0000 (14:34 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 26 Aug 2019 12:34:28 +0000 (14:34 +0200)
ext/readline/readline.stub.php
ext/readline/readline_arginfo.h
ext/standard/basic_functions.stub.php
scripts/dev/gen_stub.php

index 64b433a943a15811df43262f254219528bf9266a..ba157b54e4db55662145c284ebf0321a36dab0a4 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /** @return string|false */
-function readline(string $prompt = null) {}
+function readline(?string $prompt = null) {}
 
 /** @return mixed */
 function readline_info(string $varname = UNKNOWN, string $newvalue = UNKNOWN) {}
index e9ce57beaab17a8085d9dba3da3dca4f6e416591..43c8fbccbd8bb9cacf42117cd0d29403948cd72e 100644 (file)
@@ -1,7 +1,7 @@
 /* This is a generated file, edit the .stub.php file instead. */
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_readline, 0, 0, 0)
-       ZEND_ARG_TYPE_INFO(0, prompt, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, prompt, IS_STRING, 1)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_readline_info, 0, 0, 0)
index ea1d99f1d58571ebeff48544c6458d8a0da315eb..0da6f995663be1d6c8e149f14c398347dd244bec 100644 (file)
@@ -356,7 +356,7 @@ function inet_pton (string $ip_address) {}
 function metaphone(string $text, int $phones = 0) {}
 
 /* {{{ head.c */
-function header(string $string, bool $replace = true, int $http_response_code = null): void { }
+function header(string $string, bool $replace = true, int $http_response_code = 0): void { }
 
 function header_remove(string $name = UNKNOWN): void { }
 
index 47ff115da19857f3f712637a84359cdb3f2a9856..9fa14fc6626fbca99a18fe709794ba5301d393ad 100755 (executable)
@@ -2,6 +2,7 @@
 <?php declare(strict_types=1);
 
 use PhpParser\Node;
+use PhpParser\Node\Expr;
 use PhpParser\Node\Stmt;
 
 error_reporting(E_ALL);
@@ -38,7 +39,7 @@ function processStubFile(string $stubFile) {
         $arginfoCode = generateArgInfoCode($funcInfos);
         file_put_contents($arginfoFile, $arginfoCode);
     } catch (Exception $e) {
-        echo "Caught {$e->getMessage()} while processing $stubFile\n";
+        echo "In $stubFile:\n{$e->getMessage()}\n";
         exit(1);
     }
 }
@@ -230,6 +231,14 @@ function parseFunctionLike(string $name, Node\FunctionLike $func, ?string $cond)
             throw new Exception("Error in function $name: only the last parameter can be variadic");
         }
 
+        if ($param->default instanceof Expr\ConstFetch &&
+            $param->default->name->toLowerString() === "null" &&
+            $param->type && !($param->type instanceof Node\NullableType)
+        ) {
+            throw new Exception(
+                "Parameter $varName of function $name has null default, but is not nullable");
+        }
+
         $foundVariadic = $param->variadic;
 
         $args[] = new ArgInfo(