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 Sequences
prevPHP Mapping for Enumerations

A Slice structure maps to a PHP class containing a public variable for each member of the structure. For example, here is our Employee structure once more:

Wiki Markup
{zcode:slice}
struct Employee {
    long number;
    string firstName;
    string lastName;
};
{zcode}

The PHP mapping generates the following definition for this structure:

Wiki Markup
{zcode:php}
class Employee
{
    public function __construct($number=0, $firstName='', $lastName='');

    public function __toString();

    public $number;
    public $firstName;
    public $lastName;
}
{zcode}

The class provides a constructor whose arguments correspond to the data members. This allows you to instantiate and initialize the class in a single statement (instead of having to first instantiate the class and then assign to its members). Each argument provides a default value appropriate for the member's type. You can also declare different default values for members of primitive and enumerated types.

The mapping also includes a definition for the __toString magic method, which returns a string representation of the structure.

Ztop
See Also
Zret
Znav
nextPHP Mapping for Sequences
prevPHP Mapping for Enumerations