473,775 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can a function be called from a function?

Can a function in a class be called from another function? I create a
class object and call a method which calls another method in the same
class and I get erors.

class Nice
{
function getHi()
{
$greet = sayHi();
return $greet;
}

function sayHi()
{
return "Hi there from db.";
}
}

$greeting = new Nice()
$test = $greeting->getHi();
echo $test;

Fatal error: Call to undefined function: sayhi()

And yes I tried ->
$greet = this->sayHi(); too.

Why woun't this work? Or is this beyond the abilities of the PHP
scripting language?

Thanks for your help?
Jul 17 '05 #1
4 1999
"Bruce W...1" <br***@noDirect Email.com> wrote in message news:<3F******* ********@noDire ctEmail.com>...
Can a function in a class be called from another function? I create a
class object and call a method which calls another method in the same
class and I get erors.

class Nice
{
function getHi()
{
$greet = sayHi();
return $greet;
}

function sayHi()
{
return "Hi there from db.";
}
}

$greeting = new Nice()
$test = $greeting->getHi();
echo $test;

Fatal error: Call to undefined function: sayhi()

And yes I tried ->
$greet = this->sayHi(); too.

^^^^^
$this->sayHi();

Always, manual is your friend.

---
Our songs have meaning for everyone. I don't know of anyone who
isn't either in love, just out of love, or else wants to be in love.
--- Graham Russell, Air Supply
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2
yes, in any language
"R. Rajesh Jeba Anbiah" <ng**********@r ediffmail.com> wrote in message
news:ab******** *************** ***@posting.goo gle.com...
| "Bruce W...1" <br***@noDirect Email.com> wrote in message
news:<3F******* ********@noDire ctEmail.com>...
| > Can a function in a class be called from another function? I create a
| > class object and call a method which calls another method in the same
| > class and I get erors.
| >
| > class Nice
| > {
| > function getHi()
| > {
| > $greet = sayHi();
| > return $greet;
| > }
| >
| > function sayHi()
| > {
| > return "Hi there from db.";
| > }
| > }
| >
| > $greeting = new Nice()
| > $test = $greeting->getHi();
| > echo $test;
| >
| > Fatal error: Call to undefined function: sayhi()
| >
| > And yes I tried ->
| > $greet = this->sayHi(); too.
| ^^^^^
| $this->sayHi();
|
| Always, manual is your friend.
|
| ---
| Our songs have meaning for everyone. I don't know of anyone who
| isn't either in love, just out of love, or else wants to be in love.
| --- Graham Russell, Air Supply
| Email: rrjanbiah-at-Y!com
Jul 17 '05 #3
Seems to be ok except that there is no constructor in your class.

.b

Bruce W...1 wrote:
Can a function in a class be called from another function? I create a
class object and call a method which calls another method in the same
class and I get erors.

class Nice
{
function getHi()
{
$greet = sayHi();
return $greet;
}

function sayHi()
{
return "Hi there from db.";
}
}

$greeting = new Nice()
$test = $greeting->getHi();
echo $test;

Fatal error: Call to undefined function: sayhi()

And yes I tried ->
$greet = this->sayHi(); too.

Why woun't this work? Or is this beyond the abilities of the PHP
scripting language?

Thanks for your help?


Jul 17 '05 #4
$greeting = new Nice() needs a ;

$greet = $this->sayHi();

like this, the code works for me, even though there is still no
constructor.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
10039
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a class and a function in Python ??? Consider the following code fragments : # Fragment 1 begins a = 1
9
3697
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
3
14951
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
5
2154
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the called function, I am using p1->find(1) which is returning a valid iterator and not going to the end. I am returning p1 from the called function. But in the calling function, find(1) is going to the end, i.e unable to find the key 1, which was...
6
2544
by: gustav04 | last post by:
hi all i have a question: what is the difference between a c-function and an c++ class method (both do exactly the same thing). lets say, i have a function called print2std() and a class called CUtils with a static method called print2std()
39
6554
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
2
7678
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
3
3655
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
7
6129
by: asdf | last post by:
They looks so similar. Anybody would like to tell me their differences? Thanks a lot.
2
1637
by: Julien | last post by:
Hello all, I would like to do something like: def called(arg) if arg==True: !!magic!!caller.return 1 def caller(arg) called(arg)
0
9622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10107
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10048
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.