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 Structures
prevPHP Mapping for Built-In Types

PHP does not have an enumerated type, so a Slice enumeration is mapped to a PHP class: the name of the Slice enumeration becomes the name of the PHP class; for each enumerator, the class contains a constant with the same name as the enumerator. For example:

Wiki Markup
{zcode:slice}
enum Fruit { Apple, Pear, Orange };
{zcode}

The generated PHP class looks as follows:

Wiki Markup
{zcode:php}
class Fruit
{
    const Apple = 0;
    const Pear = 1;
    const Orange = 2;
}
{zcode}

Suppose we modify the Slice definition to include a custom enumerator value:

Wiki Markup
{zcode:slice}
enum Fruit { Apple, Pear = 3, Orange };
{zcode}

The generated PHP class changes accordingly:

Wiki Markup
{zcode:php}
class Fruit
{
    const Apple = 0;
    const Pear = 3;
    const Orange = 4;
}
{zcode}

Since enumerated values are mapped to integer constants, application code is not required to use the generated constants. When an enumerated value enters the Ice run time, Ice validates that the given integer is a valid value for the enumeration. However, to minimize the potential for defects in your code, we recommend using the generated constants instead of literal integers.

Ztop

See Also

Zret
Znav
nextPHP Mapping for Structures
prevPHP Mapping for Built-In Types