Methods Within Methods In PHP

This is something simple that I don't see explained in too many texts. I guess it's just so simple that people should get it right away. This is for the ones that don't...

Basically, use '$this' to get the method (function) working if you want to use it inside another method, but within the same class.


class Fruitcake
{
function Cashews ()
{
echo "hello cashews!";
}
function Bread ()
{
$this->Cashews();
}
}

$obj = new Fruitcake;
$obj->Bread();

The resulting output will be: "hello cashews!"

Your Ad Here
Particle Man >>> They Might Be Giants >>> 1 Year, 11 Months, 3 Weeks, 1 Day, 18 Hours, 7 Minutes

Flickr

Latest Read

feeds

Resume