Documentation for Ice 3.5. The latest release is Ice 3.7. Refer to the space directory for other releases.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 30 Next »

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:

Slice
struct Employee {
    long number;
    string firstName;
    string lastName;
};

The PHP mapping generates the following definition for this structure:

PHP
class Employee
{
    public function __construct($number=0, $firstName='', $lastName='');

    public function __toString();

    public $number;
    public $firstName;
    public $lastName;
}

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.

See Also
  • No labels