Order of evaluation of function arguments in PHP

Is the order of evaluation of arguments to a PHP function guaranteed always the same?

Thank.

+4
source share
2 answers

Usually yes. As the state of the manual :

[Function] arguments are evaluated from left to right.

But there are two extreme cases when arguments are not evaluated at all:

Undefined Functions

$calls = 0;
register_shutdown_function(function () use (&$calls) {
    echo $calls;
});
func_does_not_exist($calls++);

This displays 0 for all versions of PHP.

Missing constructor, special case of undefined function

class Foo {}

$bar = 0;
$foo = new Foo($bar++);
echo $bar;

0 PHP < 7.1 1 PHP >= 7.1. " Rasmus", . . # 67829, # 54162 # 54170.


, . , . undefined , , , undefined.

+6

:

, -. .

PHP, , , .

(, , , , ...)

+4

Source: https://habr.com/ru/post/1653316/


All Articles