Could someone clarify how to check for flags within a user defined function.
These constants are predefined glob flags.
- GLOB_BRACE
- GLOB_MARK
- GLOB_NOSORT
- GLOB_NOCHECK
- GLOB_NOESCAPE
- GLOB_ERR
- GLOB_ONLYDIR
and I have created a new one just to test.
define('GLOB_CUSTOM', 123);
I have also tried
define('GLOB_CUSTOM',0b1111011);
The results are the same.
This function does a var_dump of the flags passed.
function flags_test($flags = NULL) {
echo '$flags argument<br>';
var_dump($flags); // int 1073746108
echo '<br>';
if($flags & GLOB_BRACE){
echo 'FLAG : "GLOB_BRACE" is set';
var_dump(GLOB_BRACE);
echo '<br>';
}
if($flags & GLOB_MARK){
echo 'FLAG : "GLOB_MARK" is set';
var_dump(GLOB_MARK);
echo '<br>';
}
if($flags & GLOB_NOSORT){
echo 'FLAG : "GLOB_NOSORT" is set';
var_dump(GLOB_NOSORT);
echo '<br>';
}
if($flags & GLOB_NOCHECK){
echo 'FLAG : "GLOB_NOCHECK" is set';
var_dump(GLOB_NOCHECK);
echo '<br>';
}
if($flags & GLOB_NOESCAPE){
echo 'FLAG : "GLOB_NOESCAPE" is set';
var_dump(GLOB_NOESCAPE);
echo '<br>';
}
if($flags & GLOB_ERR){
echo 'FLAG : "GLOB_ERR" is set';
var_dump(GLOB_ERR);
echo '<br>';
}
if($flags & GLOB_ONLYDIR){
echo 'FLAG : "GLOB_ONLYDIR" is set';
var_dump(GLOB_ONLYDIR);
echo '<br>';
}
if($flags & GLOB_CUSTOM){
echo 'FLAG : "GLOB_CUSTOM" is set';
var_dump(GLOB_CUSTOM);
echo '<br>';
}
}
Test one.
flags_test(GLOB_ONLYDIR); // test one
Results
$flags argument
int 168
FLAG : "GLOB_BRACE" is set
int 128
FLAG : "GLOB_MARK" is set
int 8
FLAG : "GLOB_NOSORT" is set
int 32
FLAG : "GLOB_CUSTOM" is set
int 123
Test two.
flags_test(GLOB_CUSTOM);
Results
$flags argument
int 251
FLAG : "GLOB_BRACE" is set
int 128
FLAG : "GLOB_MARK" is set
int 8
FLAG : "GLOB_NOSORT" is set
int 32
FLAG : "GLOB_NOCHECK" is set
int 16
FLAG : "GLOB_CUSTOM" is set
int 123
I have a few questions.
- In test one why is
GLOB_CUSTOMshowing as set ? - In test two why is
GLOB_BRACE,GLOB_MARK,GLOB_NOSORTandGLOB_NOCHECKshowing as set ? - What does the value of the
var_dump($flags)represent(where did that number come from)?
How to implement a bitmask in php? is where i started, i build my example from the accepted answer. Unfortunately it doesn't explain any of the points above.
Edit :
Flags must be powers of 2 in order to bitwise-or together properly.PHP function flags, how?
This should solve the problem
define('GLOB_CUSTOM', 64);
define('GLOB_CUSTOM', 092364023760); #PHP Parse error: Invalid numeric literal in php shell code on line 1. Everything else seems as expected though.0are considered octal (See link). There is no9in that system (or8, for completeness sake), hence it's invalid. Prior to PHP7 this was silently ignored and treated as zero. See the red warning in the link. YourGLOB_CUSTOMis effectively0.