简体   繁体   English

在函数中调用的函数抛出未定义的函数错误

[英]function called in function throwing undefined function error

using the object-oriented approach, i'm trying to call a public function in a function in the same class, but it throws an error: Call to undefined function h() 使用面向对象的方法,我试图在同一类的函数中调用公共函数,但是会引发错误: Call to undefined function h()

php: 的PHP:

class Name {
    . .. .
    public function h($s) 
    {
    echo htmlspecialchars($s, ENT_QUOTES);
     }

    public function formatQuotes($row)
    {

    return "<p id=\"ab_quotes\">" . h($row['cQuotes']) . "</p>"
    . "<p id=\"ab_author\">" . h($row['vAuthor']) . "</p>";             
    }

}

what am i missing here? 我在这里想念什么?

You need to call methods in the same class using $this-> . 您需要使用$this->调用同一类中的方法。 It isn't implicit like it is in languages such as C++ 它不是像C ++这样的语言所隐含的

So, to call h 所以,叫h

$this->h($row['cQuotes']);

You must use this to access any non static member of a class from inside it 您必须使用它来从类内部访问类的任何非静态成员

{
    return "<p id=\"ab_quotes\">" . $this->h($row['cQuotes']) . 
           "</p>". "<p id=\"ab_author\">" . $this->h($row['vAuthor']) . 
           "</p>";             
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM