View Single Post
Old 04-17-2009, 11:07 PM   #1 (permalink)
allworknoplay
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default class...method question...

Ok so let's say I have a method like so....

And I pass it the first name "John".

I should get back "John Smith".

Code:
public function printName($name) {

$this->fullName = $name . " Smith";

return $this->fullName;
}
But if I do this, I think I would get back
"John Smith" too...


Code:
public function printName($name) {

$fullName = $name . " Smith";

return $fullName;
}

So my question is, what is the significance of "$this->fullName"
in the first example?

I know that it is acting as a reference (pointer) to the name "John Smith" that you are assigning it to. And that "$this->fullName" can be used locally within the method.

Is it ONLY local to the method? Or can other method's use it?

I guess I am missing the point of assigning a variable to "$this->fullName" when you can just create a variable called "$fullname" and return that?
allworknoplay is offline  
Reply With Quote