473,513 Members | 4,116 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a function defined within a funcion

Hi,

This may be the dumbest question ever, but in the following code (using
PHP 4.3.8) how do I call b() from within a()?

class test {
function a() {
print "a called";
b();

function b() {
print "b called";
}
}
}

using "b()" (as in the code above) doesn't work, neither does $this->b()
or test::b(), so how do I call it?

Thanks!

Andrew
Jul 17 '05 #1
3 2405
Andrew Boothman wrote:
Hi,

This may be the dumbest question ever, but in the following code (using
PHP 4.3.8) how do I call b() from within a()?

class test {
function a() {
print "a called";
b();

function b() {
print "b called";
}
}
}

using "b()" (as in the code above) doesn't work, neither does $this->b()
or test::b(), so how do I call it?


You will need to define the function before calling it.

Regards,

Per
Jul 17 '05 #2
"Andrew Boothman" <an*************@blueyonder.co.uk> wrote in message
news:JF***********************@news-text.cableinet.net...
This may be the dumbest question ever, but in the following code (using
PHP 4.3.8) how do I call b() from within a()?

class test {
function a() {
print "a called";
b();

function b() {
print "b called";
}
}
}

using "b()" (as in the code above) doesn't work, neither does $this->b()
or test::b(), so how do I call it?


first, you would need to define function b prior to calling it. Even when
you would do so, than you would be able to call function a only once, since
second call to a would try to define function b() which would be by that
time allready defined.

In php there is no notion of local function, as you would know it from other
languages like Pascal. The construct you are using might misslead you, that
you are defining function b local to function, but you are not, you are just
within code of a executing statement that in effect defines global function
b().

rush
--
http://www.templatetamer.com/
Jul 17 '05 #3
Per Gustafsson wrote:
Andrew Boothman wrote:
Hi,

This may be the dumbest question ever, but in the following code (using
PHP 4.3.8) how do I call b() from within a()?

class test {
function a() {
print "a called";
b();

function b() {
print "b called";
}
}
}

using "b()" (as in the code above) doesn't work, neither does $this->b()
or test::b(), so how do I call it?


You will need to define the function before calling it.


No, the function needs to be defined before you can call it - that's not the
same thing at all - unlike 'C', PHP will quite happily call functions
defined below its invocation in the source file.

To call a METHOD within an OBJECT, you need to instantiate the object and
reference the method e.g.

class test {
function a() {
print "a called";
$this->b(); // ********

function b() {
print "b called";
}
}
}
using "b()" (as in the code above) doesn't work, neither does $this->b()
or test::b(), so how do I call it?


I guess you didn't create an instance -

$testObj = new test;
$testObj->a();

HTH

C.
Jul 17 '05 #4

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

Similar topics

1
11556
by: Joel Thornton | last post by:
Is it possible to call a user-defined function without prefixing it with 'dbo.' within a SELECT clause somehow? Just curious; it's not a big issue but just a stylistic one for me. Thanks! Joel Thornton ~ <groups@joelpt.eml.cc>
1
2272
by: Red Ogden | last post by:
The following script returns an error saying document.all is null or not an object when I try to call the write_layer function more than once within the same else statement i.e.: else { write_layer('layer1', '<i>1st new base field</i>'); write_layer('layer2', '<i>2nd new base field</i>'); Id be grateful if anyone can advise me on how to...
3
2310
by: joseluismarchetti | last post by:
Hello everybody, Although I am sure this is an important question for this group, I am not sure this question belongs to this group and I will be happy to move it to the correct one after you point it to me. Direct question: How can I know if a function is defined in more than one static library that I am using to link ?
9
2805
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the code so I only have the documentation. I'm trying to call a function called z4date that, according to the docs, returns the date as "an 8-byte...
4
4072
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is dependant on data collected in the code behind on the server. I have set AutoPostback to false for the controls and added lines such as...
2
1247
by: Adam Witney | last post by:
I'd like to be able to have a PL/pgSQL function defined as SECURITY DEFINER, but still have access to the calling username within the function. Is this possible? I could pass current_user as a parameter, but of course this could easily be bypassed. Is there a way of coding this? Thanks for any help
2
1609
by: M B HONG 20 | last post by:
Hi all - I am working on a web application and have run into a problem. From a main window (Window1) I open a child window (Window2), and from that child window I open a grandchild window (Window3). I need to call a funcion that resides on Window1 from Window3. I do this successfully by calling a function with window.opener on Window3,...
1
2508
by: torbs | last post by:
I have an defined an object with a method called loadMovie that use a method - SetUrl- in an embedded quicktime object. It is embedded using the object tag, but I have also tried the embed tag. The problem is this. Although Firefox recognise the quicktime object as a HTMLObjectElement, it does not give me access to it methods from within...
1
1449
by: tuka | last post by:
Hi, I have 2 methods defined within a javascript objects that I would like to call in a third function within the same object. In the example below, func3 works well in FF but in IE7 it breaks. Any suggestions about how this may work ? I am sure this has to do with notation. I am calling the methods statically - so not instantiating a...
0
7270
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...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4757
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...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
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
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
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...

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.