Reputation: 1844
I have this code for show .log
files names and extension from directory like this:
error_2014-11-06.log
CODE:
$files = glob("../cache/logs/*.log", 1);
foreach ($files as $filename){
?>
<div><?PHP echo $filename;?></div>
<?PHP } ?>
Now i see this error :
[E_WARNING] [2] glob(): At least one of the passed flags is invalid or not supported on this platform in
Upvotes: 1
Views: 824
Reputation: 317197
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
Upvotes: 1
Reputation: 3461
$files = glob("../cache/logs/*.log", 1);
-------------------------------------^
This is not a valid flag. The available valid flags are here
Available Flags:
To use any of them, simply do
glob("path", GLOB_MARK); // example
Upvotes: 1
Reputation: 494
the second parameter (, 1) should be a constant from the following list, but you probably don't need one at all
GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR.
http://php.net/manual/en/function.glob.php
Upvotes: -1