Objects and structures
An object is a collection of named properties. A property may contain any supported value, including another object or a function. Objects are useful for grouping related values and passing them through an application as one value.
A structure is a declared template for creating objects. It defines the properties and methods that every object created from that structure will receive. An object written directly with braces has no declared structure and may be extended freely at runtime.
Object properties and methods are accessed using the object pointer,
->.
Creating objects
An empty object is written using a pair of braces:
$person = {}
Properties may also be supplied when the object is created. This notation is particularly convenient for small data objects:
$person = { forename : "Jamie", surname : "Balfour", active : true }
Objects became available in ZPE 1.4.1. Brace notation was introduced later
and replaces the older new object()
form.
Properties and nested objects
Properties can be created, read, and updated using ->:
$person = {} $person->name = "Jamie" $person->age = 33 print($person->name) $person->age = 34
Each part of a property chain must itself contain an object. Create the inner object before assigning properties to it:
$person = {} $person->address = {} $person->address->town = "Livingston" $person->address->postcode = "EH54" print($person->address->town)
Object methods
A lambda function can be stored in an object property and then called as an object method:
$counter = {value : 0} $counter->increment = function() this->value++ return this->value end function print($counter->increment())
Within an object method, this and
self refer to the object on which the method was
called.
Structure instances
A structure defines a reusable object type. Create an object from a structure
using the new keyword:
structure Person $name = null $email = null function _construct($name, $email) this->$name = $name this->$email = $email end function function get_label() return this->$name & " (" & this->$email & ")" end function end structure $person = new Person("Jamie", "jamie@example.com") print($person->get_label())
Structure instances follow the visibility and type rules declared by their structure. Unlike an anonymous object, they cannot be given arbitrary new properties that are not part of their definition.
Reference behaviour
Object variables refer to an object rather than duplicating it. Assigning an object to another variable therefore makes both variables refer to the same underlying object:
$first = {name : "Original"} $second = $first $second->name = "Updated" print($first->name) //Updated
This is normally desirable when objects represent shared state. Create an explicit copy when an independent object is required.
Inheritance
Inheritance has been part of ZPE for a long time. It allows one object type to build on another: a child structure receives the accessible properties and methods declared by its parent and may add new members or override inherited methods.
structure Animal $name = null public function describe() return "Animal: " & this->$name end function end structure structure Dog inherits Animal public function describe() return super->describe() & " (dog)" end function end structure $dog = new Dog() print($dog->describe())
The inherits and
extends keywords may both be used to declare the
parent structure.
When a child overrides a method,
super->method() calls the inherited
implementation rather than dispatching back to the override. Arguments are
passed normally, for example
super->save($path).
The inherited method runs against the same child object. Consequently,
this inside the parent method reads and updates the
child instance's properties. Lookup continues through the inheritance chain
when necessary, but private parent methods cannot be called using
super.
The inheritance system was substantially overhauled in ZPE 1.14.9, including
the introduction of super. This improved
implementation was made available in ZPE 1.14.9
(Spurriergate, September 2026).
Serialization
Objects and structure instances can be written to a file with the object's
serialise method and restored with the
deserialise
function.
$person = {name : "Jamie", active : true} $person->serialise("person.zo") $restored = deserialise("person.zo") print($restored->name)
Built-in objects
ZPE provides built-in structures for commonly used features. They are constructed and accessed using the same syntax as structures declared by an application.
$point = new Point(10, 20) $image = new Image()
Each built-in object has its own documentation describing its constructor, properties, and methods.

There are no comments on this page.
Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.
Comments powered by BalfComment