0

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?

2
  • 1
    Tip: Use ' instead of ". So you don't need to escape anything ;) Commented Jul 22, 2010 at 22:01
  • FYI, you do not need to include [keywords] in the question title. That's what tags are for. Commented Jul 22, 2010 at 22:17

2 Answers 2

4

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']);
Sign up to request clarification or add additional context in comments.

Comments

3

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

3 Comments

+1 for answering 1st (i was just about to answer similarly). tho' you gorra learn to format your code (4 spaces should do the trick) :)
its just copied from @fusions :(
using this code, all my formatting disappeared. do you know why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.