Table of Contents Previous Next
Logo
Client-Side Slice-to-PHP Mapping : 28.8 Mapping for Constants
Copyright © 2003-2010 ZeroC, Inc.

28.8 Mapping for Constants

Slice constants are mapped to PHP constants. Consider the following definitions:
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;
};
The mapping for these constants is shown below:
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);
An application refers to a constant using its flattened name:
$ans = M_TheAnswer;
Using the namespace mapping, Slice constants are mapped to PHP constants in the enclosing namespace:
$ans = \M\TheAnswer;

Table of Contents Previous Next
Logo