mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Deprecate implicit nullable parameter types (#12959)
RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types Co-authored-by: Gina Peter Banyard <girgias@php.net>
This commit is contained in:
@@ -268,6 +268,10 @@ PHP 8.4 UPGRADE NOTES
|
||||
4. Deprecated Functionality
|
||||
========================================
|
||||
|
||||
- Core:
|
||||
. Implicitly nullable parameter types are now deprecated.
|
||||
RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types
|
||||
|
||||
- Curl:
|
||||
. The CURLOPT_BINARYTRANSFER constant is deprecated.
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ class Node {
|
||||
public $parent = NULL;
|
||||
public $children = array();
|
||||
|
||||
function __construct(Node $parent=NULL) {
|
||||
function __construct(?Node $parent=NULL) {
|
||||
if ($parent) {
|
||||
$parent->children[] = $this;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ bug #71428.1: inheritance with null default values
|
||||
--FILE--
|
||||
<?php
|
||||
class A {
|
||||
public function m(array $a = null) {}
|
||||
public function m(?array $a = null) {}
|
||||
}
|
||||
class B extends A {
|
||||
public function m(array $a = []) {}
|
||||
|
||||
@@ -7,4 +7,6 @@ class B { public function m(A $a = NULL, $n) { echo "B.m";} };
|
||||
class C extends B { public function m(A $a , $n) { echo "C.m";} };
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Fatal error: Declaration of C::m(A $a, $n) must be compatible with B::m(?A $a, $n) in %sbug71428.3.php on line 4
|
||||
|
||||
@@ -3,7 +3,7 @@ Bug #72119 (Interface declaration compatibility regression with default values)
|
||||
--FILE--
|
||||
<?php
|
||||
interface Foo {
|
||||
public function bar(array $baz = null);
|
||||
public function bar(?array $baz = null);
|
||||
}
|
||||
|
||||
class Hello implements Foo {
|
||||
|
||||
@@ -18,4 +18,6 @@ function c(
|
||||
--EXPECTF--
|
||||
Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
|
||||
|
||||
Deprecated: Implicitly marking parameter $c as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Deprecated: Optional parameter $e declared before required parameter $f is implicitly treated as a required parameter in %s on line %d
|
||||
|
||||
@@ -6,7 +6,7 @@ Testing parameter type-hinted with default value inside namespace
|
||||
namespace foo;
|
||||
|
||||
class bar {
|
||||
public function __construct(\stdclass $x = NULL) {
|
||||
public function __construct(?\stdclass $x = NULL) {
|
||||
var_dump($x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ Testing parameter type-hinted (array) with default value inside namespace
|
||||
namespace foo;
|
||||
|
||||
class bar {
|
||||
public function __construct(array $x = NULL) {
|
||||
public function __construct(?array $x = NULL) {
|
||||
var_dump($x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ interface foo {
|
||||
}
|
||||
|
||||
class bar {
|
||||
public function __construct(foo $x = NULL) {
|
||||
public function __construct(?foo $x = NULL) {
|
||||
var_dump($x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ $x(new \stdclass);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $x as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
NULL
|
||||
object(stdClass)#%d (0) {
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ Testing type-hinted lambda parameter inside namespace
|
||||
|
||||
namespace foo;
|
||||
|
||||
$x = function (\stdclass $x = NULL) {
|
||||
$x = function (?\stdclass $x = NULL) {
|
||||
var_dump($x);
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ Deprecated: Optional parameter $testA declared before required parameter $testC
|
||||
|
||||
Deprecated: Optional parameter $testB declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d
|
||||
|
||||
Deprecated: Implicitly marking parameter $test2A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Deprecated: Optional parameter $test2B declared before required parameter $test2C is implicitly treated as a required parameter in %s on line %d
|
||||
|
||||
Deprecated: Implicitly marking parameter $test3A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Deprecated: Optional parameter $test3B declared before required parameter $test3C is implicitly treated as a required parameter in %s on line %d
|
||||
|
||||
@@ -69,5 +69,10 @@ namespace HTML
|
||||
echo 'Done';
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
Done
|
||||
|
||||
@@ -13,7 +13,8 @@ function bar(callable $a = null) {
|
||||
foo("strpos", 123, "strpos");
|
||||
bar("substr");
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
string(6) "strpos"
|
||||
int(123)
|
||||
string(6) "strpos"
|
||||
|
||||
@@ -10,5 +10,6 @@ function foo(X&Y $foo = null) {
|
||||
foo(null);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
NULL
|
||||
|
||||
@@ -15,4 +15,5 @@ try {
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
foo(): Argument #1 ($foo) must be of type (X&Y)|null, int given, called in %s on line %d
|
||||
|
||||
@@ -17,4 +17,6 @@ function baz(iterable $iterable = 1) {
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $iterable as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Fatal error: Cannot use int as default value for parameter $iterable of type Traversable|array in %s on line %d
|
||||
|
||||
@@ -8,6 +8,7 @@ function test(false $v = null) { return $v; }
|
||||
var_dump(test(false));
|
||||
var_dump(test(null));
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
bool(false)
|
||||
NULL
|
||||
|
||||
@@ -8,6 +8,7 @@ function test(true $v = null) { return $v; }
|
||||
var_dump(test(true));
|
||||
var_dump(test(null));
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
bool(true)
|
||||
NULL
|
||||
|
||||
@@ -7,5 +7,6 @@ function test(Foo $a = null) {
|
||||
}
|
||||
test(null);
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
ok
|
||||
|
||||
@@ -8,10 +8,10 @@ $functions = [
|
||||
'float' => function (float $f) { return $f; },
|
||||
'string' => function (string $s) { return $s; },
|
||||
'bool' => function (bool $b) { return $b; },
|
||||
'int nullable' => function (int $i = NULL) { return $i; },
|
||||
'float nullable' => function (float $f = NULL) { return $f; },
|
||||
'string nullable' => function (string $s = NULL) { return $s; },
|
||||
'bool nullable' => function (bool $b = NULL) { return $b; }
|
||||
'int nullable' => function (?int $i = NULL) { return $i; },
|
||||
'float nullable' => function (?float $f = NULL) { return $f; },
|
||||
'string nullable' => function (?string $s = NULL) { return $s; },
|
||||
'bool nullable' => function (?bool $b = NULL) { return $b; }
|
||||
];
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
|
||||
@@ -8,10 +8,10 @@ $functions = [
|
||||
'float' => function (float $f) { return $f; },
|
||||
'string' => function (string $s) { return $s; },
|
||||
'bool' => function (bool $b) { return $b; },
|
||||
'int nullable' => function (int $i = NULL) { return $i; },
|
||||
'float nullable' => function (float $f = NULL) { return $f; },
|
||||
'string nullable' => function (string $s = NULL) { return $s; },
|
||||
'bool nullable' => function (bool $b = NULL) { return $b; }
|
||||
'int nullable' => function (?int $i) { return $i; },
|
||||
'float nullable' => function (?float $f) { return $f; },
|
||||
'string nullable' => function (?string $s) { return $s; },
|
||||
'bool nullable' => function (?bool $b) { return $b; }
|
||||
];
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
|
||||
@@ -4,7 +4,7 @@ Test unresolvable inheritance check due to unavailable parameter type when the p
|
||||
<?php
|
||||
|
||||
class Test extends DateTime {
|
||||
public static function createFromFormat($format, $datetime, Wrong $timezone = null): DateTime|false {}
|
||||
public static function createFromFormat($format, $datetime, ?Wrong $timezone = null): DateTime|false {}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -8,10 +8,10 @@ interface DB {
|
||||
}
|
||||
|
||||
class MySQL implements DB {
|
||||
public function query($query, string $extraParam = null, string ...$params) { }
|
||||
public function query($query, ?string $extraParam = null, string ...$params) { }
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
===DONE===
|
||||
|
||||
@@ -8,7 +8,7 @@ interface DB {
|
||||
}
|
||||
|
||||
class MySQL implements DB {
|
||||
public function query($query, int $extraParam = null, string ...$params) { }
|
||||
public function query($query, ?int $extraParam = null, string ...$params) { }
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -7224,6 +7224,11 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
|
||||
|
||||
op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
|
||||
arg_info->type = zend_compile_typename_ex(type_ast, force_nullable, &forced_allow_nullable);
|
||||
if (forced_allow_nullable) {
|
||||
zend_error(E_DEPRECATED,
|
||||
"Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type "
|
||||
"must be used instead", ZSTR_VAL(name));
|
||||
}
|
||||
|
||||
if (ZEND_TYPE_FULL_MASK(arg_info->type) & MAY_BE_VOID) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "void cannot be used as a parameter type");
|
||||
|
||||
@@ -10,7 +10,7 @@ echo "*** Testing new DateTime() : with user space __construct magic method ***\
|
||||
|
||||
class DateTimeExt extends DateTime
|
||||
{
|
||||
public function __construct ($date = null, DateTimeZone $dtz = null)
|
||||
public function __construct ($date = null, ?DateTimeZone $dtz = null)
|
||||
{
|
||||
if($dtz === null)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ error_reporting=-1
|
||||
<?php namespace melt\core;
|
||||
|
||||
class DateTime extends \DateTime {
|
||||
public static function createFromFormat($format, $time, \DateTimeZone $timezone = null): DateTime|false {
|
||||
public static function createFromFormat($format, $time, ?\DateTimeZone $timezone = null): DateTime|false {
|
||||
return new DateTime(parent::createFromFormat($format, $time, $timezone));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class CountryMapping
|
||||
const CZ = 'CZ';
|
||||
const EN = 'EN';
|
||||
|
||||
public function get(string $countryIsoCode = null) : string // Works correctly if return type is removed
|
||||
public function get(?string $countryIsoCode = null) : string // Works correctly if return type is removed
|
||||
{
|
||||
switch (strtoupper($countryIsoCode)) {
|
||||
case 'CZ':
|
||||
|
||||
@@ -7,14 +7,14 @@ opcache
|
||||
--FILE--
|
||||
<?php
|
||||
class Schema_Base {
|
||||
public function addField($typeclass, array $params = null) {
|
||||
public function addField($typeclass, ?array $params = null) {
|
||||
$field = new $typeclass($params);
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
class Field_Base {
|
||||
public function __construct(array $params = null) {
|
||||
public function __construct(?array $params = null) {
|
||||
if (! is_array($params)) {
|
||||
$params = (array) $params;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ opcache
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function test(\SplObjectStorage $definitions = null) {
|
||||
function test(?\SplObjectStorage $definitions = null) {
|
||||
$argument = new stdClass;
|
||||
$definitions[$argument] = 1;
|
||||
$definitions[$argument] += 1;
|
||||
|
||||
@@ -10,7 +10,7 @@ opcache.jit=1205
|
||||
opcache
|
||||
--FILE--
|
||||
<?php
|
||||
function foo (int $x = null) {
|
||||
function foo (?int $x = null) {
|
||||
$a = (array)$x;
|
||||
$a[] = 42;
|
||||
var_dump($a);
|
||||
|
||||
@@ -12,7 +12,7 @@ for ($i = 0; $i < 3; $i++ ) {
|
||||
var_dump($x);
|
||||
}
|
||||
|
||||
function test(&$a = null, SomeType &$b = null) {
|
||||
function test(&$a = null, ?SomeType &$b = null) {
|
||||
$a++;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -6,7 +6,7 @@ opcache.enable_cli=1
|
||||
opcache.optimization_level=-1
|
||||
--FILE--
|
||||
<?php
|
||||
function foo(int $a = null) {
|
||||
function foo(?int $a = null) {
|
||||
$a -= 1;
|
||||
return $a;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ abstract class PHPUnit_Framework_TestCase
|
||||
private $name = null;
|
||||
private $result;
|
||||
|
||||
public function run(PHPUnit_Framework_TestResult $result = null)
|
||||
public function run(?PHPUnit_Framework_TestResult $result = null)
|
||||
{
|
||||
$result->run($this);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ Class A {
|
||||
public function privf(Exception $a) {}
|
||||
public function pubf(A $a,
|
||||
$b,
|
||||
C $c = null,
|
||||
?C $c = null,
|
||||
$d = K,
|
||||
$e = "15 chars long -",
|
||||
$f = null,
|
||||
@@ -20,6 +20,7 @@ define('K', "16 chars long --");
|
||||
echo new ReflectionClass("C"), "\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $h as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
Class [ <user> class C extends A ] {
|
||||
@@ %s 14-14
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ Bug #62715 (ReflectionParameter::isDefaultValueAvailable() wrong result)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function test(PDO $a = null, $b = 0, array $c) {}
|
||||
function test(?PDO $a = null, $b = 0, array $c) {}
|
||||
$r = new ReflectionFunction('test');
|
||||
|
||||
foreach ($r->getParameters() as $p) {
|
||||
@@ -17,6 +17,8 @@ foreach ($r->getParameters() as $p) {
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Optional parameter $a declared before required parameter $c is implicitly treated as a required parameter in %s on line %d
|
||||
|
||||
Deprecated: Optional parameter $b declared before required parameter $c is implicitly treated as a required parameter in %s on line %d
|
||||
bool(false)
|
||||
bool(false)
|
||||
|
||||
@@ -11,7 +11,7 @@ function test($nix, Array $ar, &$ref, stdClass $std,
|
||||
class test
|
||||
{
|
||||
function method($nix, Array $ar, &$ref, stdClass $std,
|
||||
NonExistingClass $na, stdClass $opt = NULL, $def = "FooBar")
|
||||
NonExistingClass $na, ?stdClass $opt = NULL, $def = "FooBar")
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ check_params(ReflectionMethod::createFromMethodName('test::method'));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $opt as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
#####test()#####
|
||||
===0===
|
||||
getName: string(3) "nix"
|
||||
|
||||
@@ -100,7 +100,8 @@ $obj->std = new stdClass;
|
||||
$r = (new ReflectionProperty($obj, 'std'))->getType();
|
||||
var_dump($r->getName());
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $d as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
*** functions
|
||||
** Function 0 - Parameter 0
|
||||
bool(true)
|
||||
|
||||
@@ -24,7 +24,8 @@ function foo(X&Y $foo = null) {
|
||||
dumpType((new ReflectionFunction('foo'))->getParameters()[0]->getType());
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
Type (X&Y)|null is ReflectionUnionType:
|
||||
Allows Null: true
|
||||
Type X&Y is ReflectionIntersectionType:
|
||||
|
||||
@@ -13,7 +13,7 @@ class Tree
|
||||
*/
|
||||
protected $head;
|
||||
|
||||
public function __construct(Node $head = null)
|
||||
public function __construct(?Node $head = null)
|
||||
{
|
||||
$this->head = $head ? : new Node('HEAD');
|
||||
}
|
||||
@@ -109,10 +109,10 @@ class Node extends \RecursiveArrayIterator implements \Countable
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @param mixed $uid
|
||||
* @param Node $parent
|
||||
* @param Node|null $parent
|
||||
* @param bool $assureUnique
|
||||
*/
|
||||
public function __construct($data, $uid = null, Node $parent = null, $assureUnique = false)
|
||||
public function __construct($data, $uid = null, ?Node $parent = null, $assureUnique = false)
|
||||
{
|
||||
if(null !== $parent) {
|
||||
$this->parent = $parent;
|
||||
|
||||
@@ -166,10 +166,10 @@ class LogReader
|
||||
*/
|
||||
public function readUntil(
|
||||
callable $matcher,
|
||||
string $notFoundMessage = null,
|
||||
?string $notFoundMessage = null,
|
||||
bool $checkAllLogs = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
if (is_null($timeoutSeconds) && is_null($timeoutMicroseconds)) {
|
||||
$timeoutSeconds = 3;
|
||||
|
||||
@@ -138,10 +138,10 @@ class LogTool
|
||||
*/
|
||||
private function match(
|
||||
callable $matcher,
|
||||
string $notFoundMessage = null,
|
||||
?string $notFoundMessage = null,
|
||||
bool $checkAllLogs = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
if ($this->getError()) {
|
||||
return false;
|
||||
@@ -169,7 +169,7 @@ class LogTool
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function checkTruncatedMessage(string $line = null): bool
|
||||
public function checkTruncatedMessage(?string $line = null): bool
|
||||
{
|
||||
if ($this->message === null) {
|
||||
throw new \LogicException('The message has not been set');
|
||||
@@ -355,7 +355,7 @@ class LogTool
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function checkLineLength(string $line, int $lineLen = null): bool
|
||||
private function checkLineLength(string $line, ?int $lineLen = null): bool
|
||||
{
|
||||
$lineLen = $lineLen ?: strlen($line);
|
||||
if ($lineLen > $this->limit) {
|
||||
@@ -569,7 +569,7 @@ class LogTool
|
||||
public function readAllEntries(
|
||||
string $type,
|
||||
string $expectedMessage,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
string $ignoreErrorFor = self::DEBUG
|
||||
): bool {
|
||||
if ($this->getError()) {
|
||||
@@ -604,12 +604,12 @@ class LogTool
|
||||
public function expectEntry(
|
||||
string $type,
|
||||
string $expectedMessage,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
string $ignoreErrorFor = self::DEBUG,
|
||||
bool $checkAllLogs = false,
|
||||
bool $invert = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
if ($this->getError()) {
|
||||
return false;
|
||||
@@ -639,7 +639,7 @@ class LogTool
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function expectDebug(string $expectedMessage, string $pool = null): bool
|
||||
public function expectDebug(string $expectedMessage, ?string $pool = null): bool
|
||||
{
|
||||
return $this->expectEntry(self::DEBUG, $expectedMessage, $pool, self::ERROR);
|
||||
}
|
||||
@@ -653,7 +653,7 @@ class LogTool
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function expectNotice(string $expectedMessage, string $pool = null): bool
|
||||
public function expectNotice(string $expectedMessage, ?string $pool = null): bool
|
||||
{
|
||||
return $this->expectEntry(self::NOTICE, $expectedMessage, $pool);
|
||||
}
|
||||
@@ -667,7 +667,7 @@ class LogTool
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function expectWarning(string $expectedMessage, string $pool = null): bool
|
||||
public function expectWarning(string $expectedMessage, ?string $pool = null): bool
|
||||
{
|
||||
return $this->expectEntry(self::WARNING, $expectedMessage, $pool);
|
||||
}
|
||||
@@ -681,7 +681,7 @@ class LogTool
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function expectError(string $expectedMessage, string $pool = null): bool
|
||||
public function expectError(string $expectedMessage, ?string $pool = null): bool
|
||||
{
|
||||
return $this->expectEntry(self::ERROR, $expectedMessage, $pool);
|
||||
}
|
||||
@@ -695,7 +695,7 @@ class LogTool
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function expectAlert(string $expectedMessage, string $pool = null): bool
|
||||
public function expectAlert(string $expectedMessage, ?string $pool = null): bool
|
||||
{
|
||||
return $this->expectEntry(self::ALERT, $expectedMessage, $pool);
|
||||
}
|
||||
@@ -716,8 +716,8 @@ class LogTool
|
||||
string $pattern,
|
||||
bool $invert = false,
|
||||
bool $checkAllLogs = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null,
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null,
|
||||
): bool {
|
||||
$matchResult = $this->match(
|
||||
function ($line) use ($pattern) {
|
||||
@@ -755,10 +755,10 @@ class LogTool
|
||||
*/
|
||||
private function getMatchDebugMessage(
|
||||
string $title,
|
||||
string $pattern = null,
|
||||
string $line = null,
|
||||
string $expectedMessage = null,
|
||||
string $actualMessage = null
|
||||
?string $pattern = null,
|
||||
?string $line = null,
|
||||
?string $expectedMessage = null,
|
||||
?string $actualMessage = null
|
||||
): string {
|
||||
$msg = "$title:\n";
|
||||
if ($pattern !== null) {
|
||||
@@ -788,10 +788,10 @@ class LogTool
|
||||
*/
|
||||
private function traceMatch(
|
||||
string $title,
|
||||
string $pattern = null,
|
||||
string $line = null,
|
||||
string $expectedMessage = null,
|
||||
string $actualMessage = null
|
||||
?string $pattern = null,
|
||||
?string $line = null,
|
||||
?string $expectedMessage = null,
|
||||
?string $actualMessage = null
|
||||
): void {
|
||||
if ($this->debug) {
|
||||
echo "LogTool - " . $this->getMatchDebugMessage($title, $pattern, $line, $expectedMessage, $actualMessage);
|
||||
@@ -820,7 +820,7 @@ class LogTool
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
private function error(string $msg, string $line = null, string $ignoreFor = self::DEBUG): bool
|
||||
private function error(string $msg, ?string $line = null, string $ignoreFor = self::DEBUG): bool
|
||||
{
|
||||
if ($this->error === null && ($line === null || ! str_contains($line, $ignoreFor))) {
|
||||
$this->trace("Setting error: $msg");
|
||||
|
||||
@@ -355,7 +355,7 @@ class Tester
|
||||
* @param string $command
|
||||
* @param string|null $expectedPartOfOutput
|
||||
*/
|
||||
static public function skipIfShellCommandFails(string $command, string $expectedPartOfOutput = null)
|
||||
static public function skipIfShellCommandFails(string $command, ?string $expectedPartOfOutput = null)
|
||||
{
|
||||
$result = exec("$command 2>&1", $output, $code);
|
||||
if ($result === false || $code) {
|
||||
@@ -397,8 +397,8 @@ class Tester
|
||||
string|array $configTemplate,
|
||||
string $code = '',
|
||||
array $options = [],
|
||||
string $fileName = null,
|
||||
bool $debug = null,
|
||||
?string $fileName = null,
|
||||
?bool $debug = null,
|
||||
string $clientTransport = 'stream'
|
||||
) {
|
||||
$this->configTemplate = $configTemplate;
|
||||
@@ -599,7 +599,7 @@ class Tester
|
||||
*/
|
||||
public function checkConnection(
|
||||
string $host = '127.0.0.1',
|
||||
string $successMessage = null,
|
||||
?string $successMessage = null,
|
||||
?string $errorMessage = 'Connection failed',
|
||||
int $attempts = 20,
|
||||
int $delay = 50000
|
||||
@@ -636,8 +636,8 @@ class Tester
|
||||
*/
|
||||
public function checkRequest(
|
||||
string $address,
|
||||
string $successMessage = null,
|
||||
string $errorMessage = null,
|
||||
?string $successMessage = null,
|
||||
?string $errorMessage = null,
|
||||
string $uri = '/ping',
|
||||
string $query = '',
|
||||
array $headers = []
|
||||
@@ -673,7 +673,7 @@ class Tester
|
||||
*/
|
||||
public function status(
|
||||
array $expectedFields,
|
||||
string $address = null,
|
||||
?string $address = null,
|
||||
string $statusPath = '/status',
|
||||
$formats = ['plain', 'html', 'xml', 'json', 'openmetrics']
|
||||
) {
|
||||
@@ -704,9 +704,9 @@ class Tester
|
||||
private function getRequestParams(
|
||||
string $query = '',
|
||||
array $headers = [],
|
||||
string $uri = null,
|
||||
string $scriptFilename = null,
|
||||
string $scriptName = null,
|
||||
?string $uri = null,
|
||||
?string $scriptFilename = null,
|
||||
?string $scriptName = null,
|
||||
?string $stdin = null,
|
||||
?string $method = null,
|
||||
): array {
|
||||
@@ -835,15 +835,15 @@ class Tester
|
||||
public function request(
|
||||
string $query = '',
|
||||
array $headers = [],
|
||||
string $uri = null,
|
||||
string $address = null,
|
||||
string $successMessage = null,
|
||||
string $errorMessage = null,
|
||||
?string $uri = null,
|
||||
?string $address = null,
|
||||
?string $successMessage = null,
|
||||
?string $errorMessage = null,
|
||||
bool $connKeepAlive = false,
|
||||
bool $socketKeepAlive = false,
|
||||
string $scriptFilename = null,
|
||||
string $scriptName = null,
|
||||
string|array $stdin = null,
|
||||
?string $scriptFilename = null,
|
||||
?string $scriptName = null,
|
||||
string|array|null $stdin = null,
|
||||
bool $expectError = false,
|
||||
int $readLimit = -1,
|
||||
int $writeDelay = 0,
|
||||
@@ -904,9 +904,9 @@ class Tester
|
||||
*/
|
||||
public function multiRequest(
|
||||
int|array $requests,
|
||||
string $address = null,
|
||||
string $successMessage = null,
|
||||
string $errorMessage = null,
|
||||
?string $address = null,
|
||||
?string $successMessage = null,
|
||||
?string $errorMessage = null,
|
||||
bool $connKeepAlive = false,
|
||||
bool $socketKeepAlive = false,
|
||||
int $readTimeout = 0,
|
||||
@@ -977,7 +977,7 @@ class Tester
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function requestValues(
|
||||
string $address = null,
|
||||
?string $address = null,
|
||||
bool $connKeepAlive = false,
|
||||
bool $socketKeepAlive = false
|
||||
): ValuesResponse {
|
||||
@@ -1010,7 +1010,7 @@ class Tester
|
||||
* @return Client
|
||||
*/
|
||||
private function getClient(
|
||||
string $address = null,
|
||||
?string $address = null,
|
||||
bool $connKeepAlive = false,
|
||||
bool $socketKeepAlive = false
|
||||
): Client {
|
||||
@@ -1119,7 +1119,7 @@ class Tester
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function signal($signal, int $pid = null)
|
||||
public function signal($signal, ?int $pid = null)
|
||||
{
|
||||
if (is_null($pid)) {
|
||||
$pid = $this->getPid();
|
||||
@@ -1405,7 +1405,7 @@ class Tester
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFile(string $extension, string $dir = null, string $name = null): string
|
||||
private function getFile(string $extension, ?string $dir = null, ?string $name = null): string
|
||||
{
|
||||
$fileName = (is_null($name) ? $this->fileName : $name . '.') . $extension;
|
||||
|
||||
@@ -1446,7 +1446,7 @@ class Tester
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefixedFile(string $extension, string $prefix = null): string
|
||||
public function getPrefixedFile(string $extension, ?string $prefix = null): string
|
||||
{
|
||||
$fileName = rtrim($this->fileName, '.');
|
||||
if ( ! is_null($prefix)) {
|
||||
@@ -1469,8 +1469,8 @@ class Tester
|
||||
private function makeFile(
|
||||
string $extension,
|
||||
string $content = '',
|
||||
string $dir = null,
|
||||
string $name = null,
|
||||
?string $dir = null,
|
||||
?string $name = null,
|
||||
bool $overwrite = true
|
||||
): string {
|
||||
$filePath = $this->getFile($extension, $dir, $name);
|
||||
@@ -1559,7 +1559,7 @@ class Tester
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
private function error(string $msg, \Exception $exception = null, bool $prefix = true): bool
|
||||
private function error(string $msg, ?\Exception $exception = null, bool $prefix = true): bool
|
||||
{
|
||||
$this->error = $prefix ? 'ERROR: ' . $msg : ltrim($msg);
|
||||
if ($exception) {
|
||||
@@ -1719,8 +1719,8 @@ class Tester
|
||||
public function expectLogPattern(
|
||||
string $pattern,
|
||||
bool $checkAllLogs = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null,
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null,
|
||||
) {
|
||||
$this->logTool->expectPattern(
|
||||
$pattern,
|
||||
@@ -1744,8 +1744,8 @@ class Tester
|
||||
public function expectNoLogPattern(
|
||||
string $pattern,
|
||||
bool $checkAllLogs = true,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null,
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null,
|
||||
) {
|
||||
if (is_null($timeoutSeconds) && is_null($timeoutMicroseconds)) {
|
||||
$timeoutMicroseconds = 10;
|
||||
@@ -1826,12 +1826,12 @@ class Tester
|
||||
private function expectLogEntry(
|
||||
string $type,
|
||||
string $message,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
int $count = 1,
|
||||
bool $checkAllLogs = false,
|
||||
bool $invert = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null,
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null,
|
||||
string $ignoreErrorFor = LogTool::DEBUG
|
||||
): bool {
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
@@ -1870,12 +1870,12 @@ class Tester
|
||||
*/
|
||||
public function expectLogDebug(
|
||||
string $message,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
int $count = 1,
|
||||
bool $checkAllLogs = false,
|
||||
bool $invert = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
return $this->expectLogEntry(
|
||||
LogTool::DEBUG,
|
||||
@@ -1906,12 +1906,12 @@ class Tester
|
||||
*/
|
||||
public function expectLogNotice(
|
||||
string $message,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
int $count = 1,
|
||||
bool $checkAllLogs = false,
|
||||
bool $invert = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
return $this->expectLogEntry(
|
||||
LogTool::NOTICE,
|
||||
@@ -1941,12 +1941,12 @@ class Tester
|
||||
*/
|
||||
public function expectLogWarning(
|
||||
string $message,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
int $count = 1,
|
||||
bool $checkAllLogs = false,
|
||||
bool $invert = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
return $this->expectLogEntry(
|
||||
LogTool::WARNING,
|
||||
@@ -1976,12 +1976,12 @@ class Tester
|
||||
*/
|
||||
public function expectLogError(
|
||||
string $message,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
int $count = 1,
|
||||
bool $checkAllLogs = false,
|
||||
bool $invert = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
return $this->expectLogEntry(
|
||||
LogTool::ERROR,
|
||||
@@ -2011,12 +2011,12 @@ class Tester
|
||||
*/
|
||||
public function expectLogAlert(
|
||||
string $message,
|
||||
string $pool = null,
|
||||
?string $pool = null,
|
||||
int $count = 1,
|
||||
bool $checkAllLogs = false,
|
||||
bool $invert = false,
|
||||
int $timeoutSeconds = null,
|
||||
int $timeoutMicroseconds = null
|
||||
?int $timeoutSeconds = null,
|
||||
?int $timeoutMicroseconds = null
|
||||
): bool {
|
||||
return $this->expectLogEntry(
|
||||
LogTool::ALERT,
|
||||
@@ -2164,7 +2164,7 @@ class Tester
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function readAllLogEntries(string $type, string $message, string $pool = null): bool
|
||||
public function readAllLogEntries(string $type, string $message, ?string $pool = null): bool
|
||||
{
|
||||
return $this->logTool->readAllEntries($type, $message, $pool);
|
||||
}
|
||||
@@ -2178,7 +2178,7 @@ class Tester
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function readAllLogNotices(string $message, string $pool = null): bool
|
||||
public function readAllLogNotices(string $message, ?string $pool = null): bool
|
||||
{
|
||||
return $this->readAllLogEntries(LogTool::NOTICE, $message, $pool);
|
||||
}
|
||||
@@ -2205,7 +2205,7 @@ class Tester
|
||||
*/
|
||||
private function trace(
|
||||
string $title,
|
||||
string|array $message = null,
|
||||
string|array|null $message = null,
|
||||
bool $isCommand = false,
|
||||
bool $isFile = false
|
||||
): void {
|
||||
|
||||
@@ -30,7 +30,7 @@ final class StreamWrapper
|
||||
string $path,
|
||||
string $mode,
|
||||
int $options = 0,
|
||||
string &$openedPath = null
|
||||
?string &$openedPath = null
|
||||
) : bool {
|
||||
if ($mode[0] !== 'r') {
|
||||
return false;
|
||||
|
||||
@@ -39,6 +39,7 @@ Test::f1(1);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $ar as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
Test::f1()
|
||||
array(1) {
|
||||
[0]=>
|
||||
|
||||
@@ -143,6 +143,11 @@ Ensure type hints are enforced for functions invoked as callbacks.
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
|
||||
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
---> Type hints with callback function:
|
||||
0: f1(): Argument #1 ($a) must be of type A, int given%s(%d)
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ $o->f(new P);
|
||||
$o->f();
|
||||
$o->f(NULL);
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Implicitly marking parameter $p as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
|
||||
object(P)#2 (0) {
|
||||
}
|
||||
-
|
||||
|
||||
Reference in New Issue
Block a user