the_velour_fog
the_velour_fog

Reputation: 2184

What do the function signatures on php.net mean?

For example when I look at the documentation for system function: it says:

string system ( string $command [, int &$return_var ] )

What does this mean? thanks

Upvotes: 1

Views: 82

Answers (4)

button
button

Reputation: 656

So for the parts of:

string system ( string $command [ , int & $return_var ]  )
1      2      3 4      5        6 7 8   9 10          11 12

in order:

  1. string - the return type
  2. system - the command name
  3. ( - the beginning of the arguments to the function
  4. string - the first argument's type
  5. $command - the first argument's name (this is just a hint, it doesn't affect how you call the function)
  6. [ - beginning of optional arguments
  7. , - this is to show that you separate arguments with a comma
  8. int - the type of the first optional argument
  9. & - indicates that the first optional argument will be passed by reference (the function can modify the passed variable **)
  10. $return_var - the name of the first optional argument
  11. ] - end of the optional arguments
  12. ) - end of the arguments to the function

It is hinting as to what might be required to call the function. So syntactically, the following are OK:

$return_type = 1;
system("String!", $return_type);
//$return_type could have changed

system("String!", $return_type);

system("String!");

But the following are not:

system();

system($var_that_wont_cast_to_string);

** PHP docs on pass by reference: http://php.net/manual/en/language.references.pass.php

Upvotes: 1

Peter Bowers
Peter Bowers

Reputation: 3093

See here for the description given within php.net itself:

http://php.net/manual/en/about.prototypes.php

Upvotes: 1

Coder-guy
Coder-guy

Reputation: 424

The listing of string or int are telling you what types of value it expects. It expects system to be of type string, an so on. If you put an int for system, you will get an error

Upvotes: -2

Thiago Elias
Thiago Elias

Reputation: 939

Means that the function name is system(), and those are the parameters and types of this function.

in this case, string $command is mandatory (and you need to pass an valid String value). When you have brackets, like in (&$return_var) is an optional parameter (& means the variable will be passed as reference, so the return value will be on the variable you pass to the function).

Upvotes: 1

Related Questions