3

I am having trouble figuring out a problem and it is because I don't know the correct terms to be searching for. Could someone please name all the parts of a PHP function and if I'm missing something please add it.

function my_function(
            non_variable $variable_one,
            $variable_two = "",
            $variable_three ) {

    /* inside stuff (Statement?) */
}

The answer I'm looking for would look something like this

function: declaration
my_function: name
non_variable: Please Answer
$variable_one: variable filled with non_variable

The one I really need to know about are non_variable and $variable_one, Thanks!


EDIT: more detail about the function

function my_function(custom_name $company) {
    $website = $company->company_website;
    /* Additional stuff */
}
MikeG
  • 314
  • 3
  • 11

3 Answers3

5
function foo(         // function declaration with function name
    SomeType $arg1,   // argument with type hint
    $arg2,            // argument
    $arg3 = ''        // argument with default value
) {                   // all above together: function signature
    // function body
}

Arguments may also be called "parameters" pretty much interchangeably. See:

deceze
  • 510,633
  • 85
  • 743
  • 889
2

non_variable = type hint or parameter type

$variable_one = argument/parameter ... of type.

Could go into more on distinction between argument and parameter but a lot of people use them interchangeably anyway... "Parameter" vs "Argument"

Additional resources:

OPP Terms

http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html - occured to me style guides would be good to glean this kind of vocab from.

Tried looking for more things geared to ESL or non native English speakers and didn't find as much as I expected. If English is your main language and its just the new vocab I think things will be easy enough anyway. If not probably good to learn them in native language, then worry about the translations.

Community
  • 1
  • 1
ficuscr
  • 6,975
  • 2
  • 32
  • 52
  • Thanks, as for **non_variable** the app I am digging through is not using it like **(int)$variable_one** - Rather it is a custom function or something other but it does have a custom name. – MikeG Nov 28 '12 at 16:51
  • to not mince words, `(int)` would be an example of *casting*. – ficuscr Nov 28 '12 at 16:54
1

non_variable is the object type expected in this parameter $variable_one is the name of the parameter used in this function

Kami
  • 19,134
  • 4
  • 51
  • 63
  • Thanks, as for **non_variable** the app I am digging through is not using it like **(int)$variable_one** - Rather it is a custom function or something other but it does have a custom name. – MikeG Nov 28 '12 at 16:53
  • non_variable - cf "Type Hint" (can be array as well as object types, and the latest PHP code also supports type hinting for scalars) – Mark Baker Nov 28 '12 at 17:02
  • 1
    you cannot use scalar types such as int or string to type hint a function. The type hinting is usually used for objects, so I expect the non_variable is referring to a class - either custom or php. See - http://php.net/manual/en/language.oop5.typehinting.php – Kami Nov 28 '12 at 17:02