Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top