I am playing with classes but have an odd problem and wondering if anyone can tell me why this is happening. I have 4 classes they all work and give the right answer but only D and M echo the text the others only echo the answer.
If you can't stand behind your troops, stand in front of them.
Semper Fidelis
Jim
Code:
<?php
class A
{
function data_insert($a,$b)
{
if (isset($this)) {
echo get_class($this).' '.$a.' plus '.$b.' = '.$a+$b;
} else {
echo "\$this is not defined.\n";
}
}
}
class S
{
function data_insert($a,$b)
{
if (isset($this)) {
echo get_class($this).' '.$a.' minus '.$b.' = '.$a-$b;
} else {
echo "\$this is not defined.\n";
}
}
}
class M
{
function data_insert($a,$b)
{
if (isset($this)) {
echo get_class($this).' '.$a.' times '.$b.' = '.$a*$b;
} else {
echo "\$this is not defined.\n";
}
}
}
class D
{
function data_insert($a,$b)
{
if (isset($this)) {
echo get_class($this).' '.$a.' divided by '.$b.' = '.$a/$b;
} else {
echo "\$this is not defined.\n";
}
}
}
$az=0;
while($az<100) {
$ax=rand(1,4);
$class=array(1=>'A',2=>'S',3=>'M',4=>'D');
$d=rand(10,100);
$e=rand(10,100);
$c = new $class[$ax]();
$c->data_insert($d,$e);
echo '<br>';
$az++;
}
?>
If you can't stand behind your troops, stand in front of them.
Semper Fidelis
Jim