Calling Class Functions from within OTHER Class Functions...
Moderator: General Moderators
-
UKSouthernLad
- Forum Newbie
- Posts: 5
- Joined: Sun Jan 04, 2009 6:12 am
Calling Class Functions from within OTHER Class Functions...
Hi
A - Can someone tell me if you can call a Class Function from within ANOTHER (Different Class) Function.
B - If this is dependant on a specific version of PHP, what version is this?
Thnx
----------------
Now playing: Mariah Carry - I miss you
via FoxyTunes
A - Can someone tell me if you can call a Class Function from within ANOTHER (Different Class) Function.
B - If this is dependant on a specific version of PHP, what version is this?
Thnx
----------------
Now playing: Mariah Carry - I miss you
via FoxyTunes
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Calling Class Functions from within OTHER Class Functions...
Do you mean call a method not a class function?
Yes you can. I dont think it is specific to a version of php, it has always been around. It just depends how you do it.
i.e. make an instance of the object...$instance = new class()...$instance->method(), or if it is static call it directly...$class::method()
Yes you can. I dont think it is specific to a version of php, it has always been around. It just depends how you do it.
i.e. make an instance of the object...$instance = new class()...$instance->method(), or if it is static call it directly...$class::method()
Re: Calling Class Functions from within OTHER Class Functions...
Inside object methods (or functions), you have access to the $this scope which is a reference of the object. You can use it to invoke other methods or access members of the object:
Code: Select all
<?php
class Dog {
public function bark() {
$this -> say('bark'); //$this is the object instance
}
public function say($text) {
echo $text;
}
}-
UKSouthernLad
- Forum Newbie
- Posts: 5
- Joined: Sun Jan 04, 2009 6:12 am
Re: Calling Class Functions from within OTHER Class Functions...
pytrin wrote:Inside object methods (or functions), you have access to the $this scope which is a reference of the object. You can use it to invoke other methods or access members of the object:Code: Select all
<?php class Dog { public function bark() { $this -> say('bark'); //$this is the object instance } public function say($text) { echo $text; } }
Thank you, but thats not quite what I need.... I need to call class functions (methods yes thanks) from methods in DIFFERENT classes.
-
UKSouthernLad
- Forum Newbie
- Posts: 5
- Joined: Sun Jan 04, 2009 6:12 am
Re: Calling Class Functions from within OTHER Class Functions...
Can *ANYONE* tell me, if it's possible to call a METHOD of CLASS "B" whilst in a METHOD OF CLASS "A"???
Re: Calling Class Functions from within OTHER Class Functions...
Yes. And there's no need to shout. 
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Calling Class Functions from within OTHER Class Functions...
Yes, PLEASE dont shout. READ http://us.php.net/manual/en/language.oop5.basic.php!!!
We are giving our time to help you!
Just create the object.
We are giving our time to help you!
Just create the object.
Code: Select all
class A {
public function a() {
echo "aaa";
$b = new b(); // create instance of object
$b->b(); // call method of object b
}
}
class B {
public function b() {
echo "bbb";
}
}
-
UKSouthernLad
- Forum Newbie
- Posts: 5
- Joined: Sun Jan 04, 2009 6:12 am
Re: Calling Class Functions from within OTHER Class Functions...
My apologies, was not my intention to shoult, merely to emphasise my points...
My problem in this case was I did not put () after $objUser->fnSearchEmail;
(WHAT A SPANNER!!! LOL)
My problem in this case was I did not put () after $objUser->fnSearchEmail;
(WHAT A SPANNER!!! LOL)
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Calling Class Functions from within OTHER Class Functions...
This is why we ask people to post code! And not pages of it, the part they think are suspect! 