The number 1
corresponds to GLOB_ERR
, which was added in PHP 5.1.0 (see Changelog section). If you get this error, you are using an outdated version of PHP.
Consider upgrading to a version that is not End of Life.
Note that you would also get this error if you had used the constant in the first place. PHP doesn't care whether you use the flag name or value. As you can see from the OPCodes, PHP will send the value to glob anyway:
Code: glob('foo', GLOB_ERR);
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename: /in/n0vqf
function name: (null)
number of ops: 4
compiled vars: none
line #* E I O op fetch ext return operands
---------------------------------------------------------------------------------
3 0 E > SEND_VAL 'foo'
1 SEND_VAL 1
2 DO_FCALL 2 'glob'
3 > RETURN 1
The reason why you want to use the constant is because it is more readable than a magic number. Also, relying on the constant is more stable in case the value gets changed for some technical reason.
You can use this code to get the values for the GLOB_*
constants:
foreach (get_defined_constants() as $k => $v) {
if (strpos($k, "GLOB") === 0) {
echo "$k => $v", PHP_EOL;
}
}
Output (PHP 5.6.15):
GLOB_BRACE => 1024
GLOB_MARK => 2
GLOB_NOSORT => 4
GLOB_NOCHECK => 16
GLOB_NOESCAPE => 64
GLOB_ERR => 1
GLOB_ONLYDIR => 8192
GLOB_AVAILABLE_FLAGS => 9303
For further reference, see the implementation of glob
at