faqts : Computers : Programming : Languages : PHP : kms : Functions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 8 people (38%) answered Yes
Recently 2 of 7 people (29%) answered Yes

Entry

How two functions in the same class communicate with each other.

Aug 22nd, 2001 07:34
marc ap neb, Kopti Kumari,


A function in a class can call another function in the same class by 
using the class function call ->.  Calling to itself use this-> as 
shown in the eg below.
Alternatively a class variable (variable scoping would be nice) can be 
set up or variables can be passed by reference from one function to 
another, again using this->someFunction(aParameter)
class Sample
{
    function fOne()
    {
        $aVariable = $this->fTwo();
        //$aVariable is set to the retuen value of fTwo and can then be 
used for whatever.
    }
    function fTwo()
    {
        //do something
        return someValue;
    }
}