我的代码有问题:
declare(strict_types=1);
class TextModifications
{
static public function readValue(string $string): string
{
return $purifier->purify($string);
}
static public function saveValue(string $string): string
{
return $string;
}
}
$TextModifications = new TextModifications();
$TextModifications->saveValue($_POST["login"])
我有错误: 致命错误:Uncaught TypeError: Argument 1 passed to TextModifications::saveValue() must be the type string, null given, called in /Applications/XAMPP/xamppfiles/htdocs/1.php on line 21 and defined in /Applications/ XAMPP/xamppfiles/htdocs/1.php:11 堆栈跟踪:#0 /Applications/XAMPP/xamppfiles/htdocs/1.php(21): TextModifications::saveValue(NULL) #1 {main} throw in /Applications/XAMPP /xamppfiles/htdocs/1.php 第 11 行
我有 PHP 7.2.
有谁知道如何解决这个问题?
似乎您将 NULL 作为第一个参数传递给需要字符串参数的函数。在调用函数之前检查变量
$_POST['login']
是否为 null 或接受 null 值。这取决于您想在哪里验证输入数据。