Use one function to call another

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tehquickness
Forum Commoner
Posts: 32
Joined: Mon Oct 24, 2005 11:31 pm

Use one function to call another

Post by Tehquickness »

I have a quick question, if I have a function can i use it to call other functions outside of itself?
Example

Code: Select all

class DailyActivities{
     var $something;
     var $somethingelse;

   function Day($whichday){
      $this->something = gotoWork();
      $this->somethingelse = gotoSchool();

}

   function gotowork(){
      return $var;
}

   function gotoSchool(){
      return $anothervar;
}
}

this way when the function Day() is called, it will activate and execute the other functions. Is that possible or does the I want to be called have to be inside the function I am already using?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Functions can call other functions. Methods can call other methods and functions. The code you posted would be a method to method call. When calling another method of the same class $this-> should be used if you want to refer to the current (active) instance of the class (i.e. object)
Tehquickness
Forum Commoner
Posts: 32
Joined: Mon Oct 24, 2005 11:31 pm

Post by Tehquickness »

Awesome. That is just what I needed. Thanks for the help.
Post Reply