Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Znav
nextPHP Mapping for Exceptions
prevPHP Mapping for Dictionaries

A Slice constant maps to a PHP constant. Consider the following definitions:

Wiki Markup
{zcode:slice}
module M {
    const bool      AppendByDefault = true;
    const byte      LowerNibble = 0x0f;
    const string    Advice = "Don't Panic!";
    const short     TheAnswer = 42;
    const double    PI = 3.1416;

    enum Fruit { Apple, Pear, Orange };
    const Fruit     FavoriteFruit = Pear;
};
{zcode}

The mapping for these constants is shown below:

Wiki Markup
{zcode:php}
define('M_AppendByDefault', true);
define('M_LowerNibble', 15);
define('M_Advice', "Don't Panic!");
define('M_TheAnswer', 42);
define('M_PI', 3.1416);
define('M_FavoriteFruit', M_Fruit::Pear);
{zcode}

An application refers to a constant using its flattened name:

Wiki Markup
{zcode:php}
$ans = M_TheAnswer;
{zcode}

Using the namespace mapping, Slice constants are mapped to PHP constants in the enclosing namespace:

Wiki Markup
{zcode:php}
$ans = \M\TheAnswer;
{zcode}
Ztop
See Also
Zret
Znav
nextPHP Mapping for Exceptions
prevPHP Mapping for Dictionaries