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?

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top