input
input

Reputation: 7519

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()

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?

Upvotes: 0

Views: 206

Answers (2)

Sadat
Sadat

Reputation: 3501

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>";             
}

Upvotes: 3

Yacoby
Yacoby

Reputation: 55445

You need to call methods in the same class using $this->. It isn't implicit like it is in languages such as C++

So, to call h

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

Upvotes: 4

Related Questions