views:

51

answers:

2

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?

+3  A: 

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']);
Yacoby
i tried the code, and all my formatting in css disappeared.
fuz3d
+3  A: 

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>";             
}
Sadat
+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) :)
jim
its just copied from @fusions :(
Sadat
please see my above comment.
fuz3d
using this code, all my formatting disappeared. do you know why?
fuz3d
:) for extra spaces, i have used to looks good here :(
Sadat