<?php
namespace Bar {
const BAR_E_ERROR = 42;
function foo($value = E_ERROR) {}
function bar($value = \E_ERROR) {}
function baz($value = BAR_E_ERROR) {}
}
namespace {
function foo($value = E_ERROR) {}
error_reporting(E_ALL);
$list = array('foo', 'Bar\foo', 'Bar\bar', 'Bar\baz');
foreach ($list as $functionName) {
$ref = new ReflectionParameter($functionName, 'value');
echo "Checking parameter for $functionName", PHP_EOL;
var_dump($ref->getDefaultValueConstantName(), $ref->getDefaultValue());
echo PHP_EOL;
}
}
- Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- Checking parameter for foo
string(7) "E_ERROR"
int(1)
Checking parameter for Bar\foo
string(11) "Bar\E_ERROR"
int(1)
Checking parameter for Bar\bar
string(7) "E_ERROR"
int(1)
Checking parameter for Bar\baz
string(15) "Bar\BAR_E_ERROR"
int(42)
preferences:
111.79 ms | 404 KiB | 198 Q