Uncaught错误:调用未定义的函数。即使该功能确实存在[PHP] [关闭]

问题描述 投票:-1回答:2

欢迎大家!我用PHP编码CMS,遇到以下问题:

我有一个名为'AddingArticle'的类,并且有一个构造方法__construct(...)。

__ construct(...)的代码:

public function __construct(string $title, string $photo, string $content, string $articleUrl, string $author, string $category, ?string $additionalCategory = null, ?string $publicationDate = null){

    echo '<br>'.$title.'<br>';

    $this->title = santizeInput($title);
    echo ("<br>TEST 1 - passed");

    $this->photo = $this->santizeInput($photo);
    echo ("<br>TEST 2 - passed");

    $this->content = $this->santizeInput($content);
    echo ("<br>TEST 3 - passed");


    $this->articleUrl = $this->santizeInput($articleUrl);
    echo ("<br>TEST 4 - passed");

    $this->author = $this->santizeInput($author);
    echo ("<br>TEST 5 - passed");

    $this->category = $this->santizeInput($category);
    echo ("<br>TEST 6 - passed");
}

并且在同一类中有一个称为santitizeInput()的方法:

 public function sanitizeInput(string $input): string {
    return filter_var($input, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}

我不断收到错误:致命错误:未捕获错误:调用未定义的方法AddingArticle :: santizeInput()

我用值填充了构造函数的所有余项,并且再次发生。我知道操作者可能会尝试找到方法sanitizeInput()(不带任何参数),但是不应该。

我研究了这种方法:echo method_exists('AddingArticle','sanitizeInput');并返回1(其值为true)。此外,每次使用__consturct(...)中的$ title变量时,它都会显示一个适当的值,然后会弹出致命错误。我不知道怎么了。我真的很感谢每一个帮助!

php oop fatal-error
2个回答
-1
投票

是类型错误,它是sanitizeInput,您正在调用santizeInput。请确保代码中的所有代码都正常。


-1
投票

您有一个santizeInputsanitizeInput的错字,并且您也在全局范围内而不是$this->title = santizeInput($title);上调用了$this->sanitizeInput()

© www.soinside.com 2019 - 2024. All rights reserved.