In drupal|menu.inc, I found the constant was defined in Hexadecimal :
define('MENU_IS_ROOT', 0x0001)
why not
define('MENU_IS_ROOT', 1)
==================================
there is another code snippet:
define('MENU_VISIBLE_IN_BREADCRUMB', 0x0004);
define('MENU_SUGGESTED_ITEM', MENU_VISIBLE_IN_BREADCRUMB | 0x0010);
is it equal MENU_SUGGESTED_ITEM = MENU_VISIBLE_IN_BREADCRUMB = 16 ?
It's for bitwise operations
You can do something like this:
<?php
define("FLAG_ONE", 0x0001);
define("FLAG_TWO", 0x0002);
define("FLAG_THREE", 0x0004);
define("FLAG_FOUR", 0x0008);
define("FLAG_ALL", FLAG_ONE|FLAG_TWO|FLAG_THREE|FLAG_FOUR);
function make_waffles()
{
echo 'Yummy! We Love Waffles!!!';
}
function do_something($flags)
{
if ($flags & FLAG_TWO)
make_waffles();
}
$flags |= FLAG_TWO;
do_something($flags);
?>
BTW, you can check this answer to know when it's better to use const or define.
Hex constants are often used for bit masks. When you're defining all the values, it makes it easy to see the bit pattern relationships.
The resulting values are the same, it just makes the code easier to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With