PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fendtele83
Forum Commoner
Posts: 27 Joined: Tue Oct 25, 2005 2:21 pm
Location: Woodbridge, NJ
Post
by fendtele83 » Tue Jan 10, 2006 2:59 pm
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????
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jan 10, 2006 3:04 pm
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 .
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Tue Jan 10, 2006 3:06 pm
you have to let it know where the function is...
Code: Select all
function call_hi()
{
$this->print_hi();
}
fendtele83
Forum Commoner
Posts: 27 Joined: Tue Oct 25, 2005 2:21 pm
Location: Woodbridge, NJ
Post
by fendtele83 » Tue Jan 10, 2006 3:09 pm
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...
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Jan 10, 2006 4:11 pm
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();