func_get_arg() Changed Behavior

func_get_arg() and func_get_args() used to report the calling value of the argument, until PHP 7.

Since PHP 7, it is reporting the value of the argument at calling time, which may have been modified by a previous instruction.

This code will display 1 in PHP 7, and 0 in PHP 5.

PHP code

<?php

function x($a) {
    print func_get_arg(0);  // 0
    $a++;
    print func_get_arg(0);  // 1
}

x(0);
?>

Before

00

After

01

PHP version change

This behavior changed in 7.2