Page 1 of 1

Classes in PHP

Posted: Tue Feb 24, 2004 1:51 am
by phppick
class Test{
function Test(){
echo "FirstName";
}

function TestMe(){
echo " LastName";
}
}

$sun=new Test();

function Find($var){
$sun->TestMe(); //-----------***
echo $var;echo "<br>";
echo "Some text";
}

call_user_func('Find',$variable);

It is giving Error: at (***) line AS

Fatal error: Call to a member function on a non-object

anybody?? i am posting again becuase my previous post is not Clear

Thanks
Jen

Posted: Tue Feb 24, 2004 1:58 am
by saeen
im not very good at php im a begginer but well jus tryen to help
assumin that this class u have made and the place whr u have called it are two different files i would say u jus need to require_once("test.php");
or include("test.php")
and thats it umm i hope
anywayz jus tryen to help man forgive me if im wrong

Posted: Tue Feb 24, 2004 3:37 am
by McGruff
Please don't repeat the same question in a new topic.

I think the answer was given in the first topic which you started (you haven't passed $sun into the function). Any further questions - for example if you're not sure about variable scope - please post in the original topic.

Posted: Tue Feb 24, 2004 7:21 am
by evilMind

Code: Select all

<?php
$sun = new Test();

function Find($var){
   global $sun;
   $sun->TestMe(); //-----------***
   echo $var;echo "<br>";
   echo "Some text";
}
?>
the "Find" function can't find the variable $sun becaus of it's scope limitation see [url]http://us2.php.net/manual/en/language.v ... .scope.php for more information on variable scope

Thanks

Posted: Tue Feb 24, 2004 8:08 pm
by phppick
i got Problem cleared, Thanks