Learn

Each of these features can be used on their own, and installed via Composer. While they may resemble syntax from modern languages, it's important to understand how they differ.

Class accessors

You type

Pre generates

You type

Pre generates

Deferred

You type

Pre generates

You type

Pre generates

Immutable classes

You type

Pre generates

You type

Pre generates

Parameter loaders

You type

Pre generates

Property loaders

You type

Pre generates

You type

Pre generates

Short closures

You type

Pre generates

Plugin

Macros are applied to Pre processed files. Each feature library you install adds its own macro file(s). You can see which macro files are currently added, using the Pre\getMacroPaths function.

These files are written in Yay syntax. If you'd like to learn how this syntax works, take a look at the Pre plugins, or the Yay tests. It's tricky, but well worth it to get your favourite syntax without writing a line of core code.

If you want to add your own macros to the mix, use the Pre\addMacroPath function. Point it to your macro files, and they'll be used when file are compiled.

Similarly, if you no longer want to apply a macro (yours or from a feature library), try the Pre\removeMacroPath function. The path you supply needs to be exactly the same as the path returned by the Pre\getMacroPaths function.

Pre is opt-in, which means you need to rename your path/to/file.php files to path/to/file.pre. This extension makes them visible to the Pre autoloader, which will include all registered macro files, compile them to valid PHP syntax, and format these compiled files to PSR-2.