Classes in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

Classes in PHP

Post 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
saeen
Forum Newbie
Posts: 24
Joined: Mon Sep 22, 2003 5:35 am
Contact:

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post 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
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

Thanks

Post by phppick »

i got Problem cleared, Thanks
Post Reply