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,
->.
Not every built-in object is directly constructable in YASS. Some objects are
returned by a function call or created by the web runtime, such as
Request, Response, and UploadedFile.
Creating objects
An empty object is written using a pair of braces:
$person = {}
When a root object or an intermediate member may be null, use the
null-safe object pointer ?->. The chain stops safely and returns
null when the value before the operator is unavailable. The
null-safe form was introduced in ZPE 1.14.11.
$name = $root?->inner?->get_name()
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).
Persistence and storage
The legacy object serialise method and the
deserialise function were removed in ZPE 1.14.11. The
serialize and deserialize aliases were removed as
well; they are no longer available for storing objects or structure
instances.
Use the versioned Storage module
instead. Its Storage::save() and Storage::open()
functions use ZPE's native storage format and support ordinary ZPE values,
including objects and structures.
$person = {name : "Jamie", active : true} Storage::save("person.zps", $person) $restored = Storage::open("person.zps") print($restored->name)
Built-in objects
ZPE provides built-in objects for commonly used features. Constructable
objects use the same new syntax as structures
declared by an application, while runtime-created objects are returned by
functions or supplied by the web environment.
$point = new Point(10, 20) $image = new Image()
Each built-in object has its own documentation describing its constructor, properties, and methods.
Member access after construction (ZPE 1.14.11+)
The object pointer may be used immediately after a new expression. This is
useful for a temporary object when only one method call or property access is needed.
if (new File("library.json")->exists()) $library = json_decode(new File("library.json")->read()) end if

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