473,656 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling a method from within a class??

hi all,

just wondering what the syntax is for calling a method of a class from
another method of that same class?

for example...

class Test {
var $test="foo";
function printTest() {
print $this->test;
}
function callMethod() {
// call the printTest() function
}
}

what is the code i need to put in the callMethod() method to call the
printTest() method???

thanks in advance

JP
Jul 17 '05 #1
2 2056
kingofkolt wrote:
just wondering what the syntax is for calling a method of a class from
another method of that same class?

for example...

class Test {
var $test="foo";
function printTest() {
print $this->test;
}
function callMethod() {
// call the printTest() function
}
}

what is the code i need to put in the callMethod() method to call the
printTest() method???


$this->printTest();

Chris

--
Chris Hope
The Electric Toolbox Ltd
http://www.electrictoolbox.com/
Jul 17 '05 #2
"Chris Hope" <bl*******@elec trictoolbox.com > wrote in message
news:40******** @news.athenanew s.com...
kingofkolt wrote:
just wondering what the syntax is for calling a method of a class from
another method of that same class?

for example...

class Test {
var $test="foo";
function printTest() {
print $this->test;
}
function callMethod() {
// call the printTest() function
}
}

what is the code i need to put in the callMethod() method to call the
printTest() method???


$this->printTest();

Chris

--
Chris Hope
The Electric Toolbox Ltd
http://www.electrictoolbox.com/


well that was simple enough... thx!!

JP
Jul 17 '05 #3

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

Similar topics

3
2410
by: Andrew Boothman | last post by:
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();
4
9628
by: Murat Tasan | last post by:
i have a quick question... is there a way to obtain the reference to the object which called the currently executing method? here is the scenario, i have a class and a field which i would like to populate with a reference to the object that constructed this current object. i would attempt to accomplish this by setting the appropriate field from within the constructor... i figured it might be obtainable from the stack trace, but that...
3
3928
by: acg | last post by:
If you have a class with a public method, and another class which will want to call this method, is there a way to determine the type of the calling class within the method being called? For I want to gaurantee only certain other classes/object types can call a specific method in given class. Any advice would be appreciated and if there is anything that can be done to use the frameworks inherent permissioning. Regards, acg
5
3085
by: Bennett Haselton | last post by:
I've noticed that if you enter the following code in the codebehind page for an .aspx page, it won't compile because the call to Trace.Write() is not valid except in methods of a class derived from System.Web.UI.Page. Two questions: 1) I don't know much about C# but I was under the impression that if certain classes and functions were available in a namespace (as the result of a "using" statement at the top of a file), then they were...
5
3414
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
8
5356
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script> sections? I can't seem to figure out the syntax for for calling code-behind directly. The method is within the class my page inherits from and is public, but when I try to call it from my page I get this error: CS1520: Class, struct, or...
3
4702
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC application. Furthermore, I use a pointer to an unmanaged function to jump back into the managed dll. The managed part is basically a remoting enhancement which asynchronly
1
2028
by: samdediacre | last post by:
Hi all, I have developped a very simple Windows service that references a managed .NET dll. the code within the dll contains a static class to read/write data from registry. So the OnStart() method of the service simply calls the dll to read info from registry, but the static method reading info fails to execute... the dll tested within a console or winform application works fine (i can call the static class and get the info i want) So i...
7
2003
by: =?ISO-8859-1?Q?Fernando_G=F3mez?= | last post by:
Hello all. I have this class with a virtual method and a constructor that calls this virtual method. A derived class overrides this virtual method, so I expected that when the base's constructor is called, it would call the derived version of the method. However, it does not, it calls the base's version. An example: class Base { public: Base() {
9
3248
by: Pubs | last post by:
Hi all, I want to call a function with some intial parameters with in a thread. At the end of the function execution it should return a value to the caller. Caller is outside the thread. Example function test (int a, int b);
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8498
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,...
0
8600
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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
5629
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
4150
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.