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:
struct Employee { long number; string firstName; string lastName; };
The PHP mapping generates the following definition for this structure:
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.