Question re: Classes & Functions

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
saturnprods
Forum Newbie
Posts: 1
Joined: Mon Aug 04, 2008 10:02 pm

Question re: Classes & Functions

Post by saturnprods »

Hey everyone. I am learning to use classes.

I have run into a confusion -

Look at this breakdown:

***** PLEASE USE THE

Code: Select all

TAG *****[/color]

Code: Select all

class MyClass{
 
function functionA{
do this;
return that;
}
 
function functionB($variable){
 
$apple =  functionA($variable);
$apple .= '123';
return $apple;
 
}
 
}
----

This is a really simplified example to show the structure. My question is, when I call the Function A in Function B, do I need to do it some other way than the way a regular function is called? I am not sure about this.

Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Question re: Classes & Functions

Post by Christopher »

Code: Select all

class MyClass {
     protected $that = 0;
 
     function functionA() {
          $this->that = do_this();     // function outside the class
          return $this->that;
     }
 
     function functionB($variable) {
          $apple = $this->functionA($variable);   // method of class
          $apple .= '123';
          return $apple;
     }
}
(#10850)
Post Reply