I'm sure its possible to call functions from other functions, but it is not working for me. Is there some syntax someone can provide to me as an example of calling a function within another function?
Also, both of these functions are in the same class. I have not declared any functions in this class as public or private. Do functions in a class default to private? Or do functions default to public? If they are public by default, are functions in the same class in each other's scope?
I think public is default..., but i also think that public and private visibility declaration on functions is only available as of php 5, and a lot of people still use php 4...so you may not need to declare depending on your target and enough planning.
My question is if i call funtion_two will it return a value of 18? If this is possible is my syntax right? I'm basically doing this, but more complicated and its not working.
A function defined in a class does not "exist" only by its function name, you must reference it via the "->" operator as a member of an object, or statically via the "::" operator as a class member. Therefore in your example you would want to use the special "$this" variable to indicate that the function is a method of the current object:
PHP Code:
$output_two = $this->function_one($send);
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
A function defined in a class does not "exist" only by its function name, you must reference it via the "->" operator as a member of an object, or statically via the "::" operator as a class member. Therefore in your example you would want to use the special "$this" variable to indicate that the function is a method of the current object:
PHP Code:
$output_two = $this->function_one($send);
Correct me if I'm wrong, but isn't the above what was said earlier
Code:
yes, private and public delarations of class variables and functions is available in php5
Imo it's good practice to declare a variable or function private/public regardless of the default....but that's just me :)
To call a function with a class file in php5 use:
Code:
$this->functionName(arg1,arg2,argN);
Correct me if I'm wrong, but isn't the above what was said earlier
Yes, it was said, but apparently not understood, so I tried again in the hopes that this time it might be.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks