Question

What is actually happening when I do something like this:

return $this->errors[] = __FUNCTION__;

Is it assigning the value to the variable and then returns if success or not, or does it assign the value to the array and return back the assigned value as well?

Était-ce utile?

La solution

What will happen is:

a new element will be added to this array $this->errors with the name of the enclosing function name and the last assigned value will be returned.

For example:

$errors = array();

function test() {
    global $errors;
    return $errors[] = __FUNCTION__;
}

var_dump(test());

the output will be test, not an array.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top