Modern PHP Syntax in Trongate
In recent years, PHP has evolved rapidly, introducing features like type hints, return types, doc blocks, and constructor property promotion. When used thoughtfully, these can improve code quality and help prevent bugs.
Trongate fully supports all modern PHP syntax. However, you’ll notice that the examples in this documentation keep things deliberately simple. This is intentional.
Why This Documentation Uses Simple Syntax
Trongate’s documentation focuses on teaching framework concepts, not PHP language features. For that reason, examples are often simplified for brevity. For example:
...instead of:
Both versions are valid. The simpler one helps readers focus on how Trongate works rather than PHP syntax. In your production code, however, you’re encouraged to use the modern version.
Modern PHP Features at a Glance
| Feature | Purpose | Recommendation |
|---|---|---|
| Access Modifiers | Control visibility (public, protected, private) |
Use in all class methods for clarity |
| Type Hints | Define parameter types | Use when arguments are expected to be of pre-defined types |
| Return Types | Define what a method returns | Use to ensure methods return values of expected types |
| Doc Blocks | Describe methods, parameters, and return values | Use for complex or public-facing methods |
| Constructor Property Promotion | Declare and assign class properties directly in the constructor | Use in custom classes where suitable |
When to Use Modern Syntax
- Public-facing APIs: Always use type hints, return types, and doc blocks.
- Shared or complex logic: Add documentation and strict typing.
- Critical systems: Security, payments, and data handling benefit from strict typing.
When Simplicity Wins
- Quick prototypes and early-stage development
- Internal helpers with clear intent
- One-off scripts or debugging tasks