Click here to Skip to main content
15,914,905 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Examples:

PHP
//function with Parameters

  public function Name($fname, $lname) {

     return $fname . ' ' . $lname;

  }


//function without Parameters

  public $fname;
  public $lname;


  public function Name() {

    return $this->fname . ' ' . $this->lname;

  }


What I have tried:

please Just answer my question, It's quite hurtful to be ignored so please it doesn't matter if its accurate or not, I just want the idea's, concepts about it. so please don't be a arrogant prideful ass. [EDITED]
Posted
Updated 19-Oct-18 5:10am
v5
Comments
CPallini 19-Oct-18 4:21am    
"so please don't be a arrogant prideful ass"
Sorry?!
Leo Chapiro 19-Oct-18 4:34am    
Maybe bad experienses in other forums, I can't imagine that was someone of us :)
CPallini 19-Oct-18 4:51am    
A bit odd, as preventive measure.
Leo Chapiro 19-Oct-18 5:11am    
Yea, a kind of "aggressive" defense :)
Richard MacCutchan 19-Oct-18 7:22am    
"so please don't be a arrogant prideful ass."
Yeah, maybe you should try that yourself.

Further to the other solutions but picking up on your comment
Quote:
I heard the phrase the best function are those without parameters
I suspect someone has said this in respect of using classes. They were probably trying to get over that you should use the (internal) properties of the class within it's methods and functions rather than relying on external data passed into (the class).

This is a very narrow view of the use of functions and would usually mean that you have to have an instance of the class in order to do anything with the functions. But having static "helper" classes can also bring its own problems. There is a good discussion on that topic here[^] - see the solution by Mark Rasmussen.

There is no one-size-fits-all solution and what one person thinks of as "best" in one scenario may not be the best for another scenario. Your ability to judge this for yourself will increase with practise
 
Share this answer
 
Your question is tagged with "PHP" but I think this is a generic question, not dependend on a special programming language.

If you don't use the parameters in your function, it is very "static" so to say.
By using the parameters you can use your function more versatile.

Jusat imagine, you want to write a function that adds two integers.
Is it not simple, to use this two integers as the parameters of the function?
 
Share this answer
 
v3
Simple: a function with parameters can work on data entirely internally, it doesn't rely on external values.
Think of it like this - if you wrote an addition function writing it without parameters makes it clumsy to use:
1) Load left value into variable1
2) Load right value into variable2
3) Call function.
With parameters, it's a lot cleaner:
1) Call function passing left and right values.

It also means that recursive functions can work: where a function is defined in terms of itself:
factorial (n): where n > 1 then n * factorial(n - 1) else 1
To do that with variables is a lot more complex, because you need to save the value of n in a stack of some form yourself to prevent you messing up previous incarnations.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900