Page 1 of 1
OOP, calling methods from within methods
Posted: Tue Jan 10, 2006 2:59 pm
by fendtele83
how do i do it in a php4 compatible environment... this is what im trying to do:
Code: Select all
class say_hi {
function print_hi()
{
echo "hi";
}
function call_hi()
{
print_hi();
}
}
$sayHi = new say_hi();
$sayHi->call_hi();
i get this error: Fatal error: Call to undefined function: print_hi() in say_hi.class.php on line 151
what's the deal????
Posted: Tue Jan 10, 2006 3:04 pm
by feyd
Code: Select all
class say_hi {
function print_hi()
{
echo "hi";
}
function call_hi()
{
$this->print_hi();
}
}
$sayHi = new say_hi();
$sayHi->call_hi();
Moved to
PHP - Code.
Posted: Tue Jan 10, 2006 3:06 pm
by wtf
you have to let it know where the function is...
Code: Select all
function call_hi()
{
$this->print_hi();
}
Posted: Tue Jan 10, 2006 3:09 pm
by fendtele83
duuuuhhhhhh.... haha, thanks...
that was actually the first thing i tried... but i used a search and replace and actually replaced the function name with $this->functionName as well... that's why i didnt get it to work...
Posted: Tue Jan 10, 2006 4:11 pm
by Jenk
for static calling (iirc):
Code: Select all
class say_hi {
function print_hi()
{
echo "hi";
}
function call_hi()
{
self::print_hi();
}
}
say_hi::call_hi();