Using oop php methods on your sites will make coding practices cleaner and more adaptable for your needs.
It will keep security in check. Below is a simple example for those just starting out with object orientated design:
//Define class
class robot {
//Define variables var $eaten;
//Define the function buzz()
//notice no parameters
function buzz()
{
//Define the variable
$sound ='Buzzzzzzzz<br/>';
return $sound;
}
function eat_nutsnbolts($colour)
{
if ($colour == 'grey')
{
// robot is happy
$this->eaten = true;
return $this->buzz();
}
}
function make_oil()
{
if ($this->eaten)
{
return 'Oil produced<br/>';
}
else
{
return 'Robot has not eaten yet<br/>';
}
}
}
// Create the robot object Metropolis
$Metropolis = new robot; echo $Metropolis->buzz();
echo $Metropolis->make_oil(); // robot has not eaten yet $Metropolis->eat_nutsnbolts('grey');
echo $Metropolis->make_oil(); // Oil produced