while i was testing php OOP features ....
try this code:
<?
class class1{
function quote(){
echo("says:'");
}
}
class class2{
function say($name,$object,$string){
print($name.$object->quote().$string."'.");
}
}
$obj1=new class1();
$obj2=new class2();
$obj2->say("descartes ",$obj1,"i think therefore i am");
?>
you'll get this output:
says:'descartesi think therefore i am'.
but the desired output is:
descartes says : ' i think therefore i am '.
that simply can be achieved by this code :
<?
class class1{
function quote(){
echo("says:'");
}
}
class class2{
function say($name,$object,$string){
print($name);
print($object->quote());
print($string."'.");
}
}
$obj1=new class1();
$obj2=new class2();
$obj2->say("descartes ",$obj1,"i think therefore i am");
?>
But what is the problem in first code
try this code:
<?
class class1{
function quote(){
echo("says:'");
}
}
class class2{
function say($name,$object,$string){
print($name.$object->quote().$string."'.");
}
}
$obj1=new class1();
$obj2=new class2();
$obj2->say("descartes ",$obj1,"i think therefore i am");
?>
you'll get this output:
says:'descartesi think therefore i am'.
but the desired output is:
descartes says : ' i think therefore i am '.
that simply can be achieved by this code :
<?
class class1{
function quote(){
echo("says:'");
}
}
class class2{
function say($name,$object,$string){
print($name);
print($object->quote());
print($string."'.");
}
}
$obj1=new class1();
$obj2=new class2();
$obj2->say("descartes ",$obj1,"i think therefore i am");
?>
But what is the problem in first code