Skip to main content
David Dew Mallick

David Dew Mallick

ProjectsExperienceSkillsBlog
Back to blog
php property hooksphp asymmetric visibilityphp pipe operatorlaravel php 8.5

PHP 8.5 Features for Laravel Developers

PHP 8.5 introduces property hooks, asymmetric visibility, and the pipe operator. Learn how to use these features to write cleaner, more robust Laravel code.

Sep 28, 2026 · 5 min read

PHP 8.5 moves several patterns from framework boilerplate into the language itself. Property hooks eliminate repetitive getters and setters, asymmetric visibility enforces read-only public state, and the pipe operator composes transformations cleanly. These changes reduce the surface area for bugs in Laravel applications and make Eloquent models more expressive.

Key Takeaway

Upgrade your PHP version and enable the features in your php.ini. Refactor one model or service class per pull request to adopt property hooks and asymmetric visibility. Use the pipe operator for data transformation pipelines instead of chained method calls.

What are PHP property hooks?

Property hooks let you define custom logic that runs when a property is read (get) or written (set) without creating a separate method. The syntax is compact and the logic lives inside the class definition. This is a significant change for Laravel developers who have relied on Eloquent mutators and accessors for years.

class User
{
    public string $name {
        get => $this->name;
        set (string $value) {
            $this->name = trim($value);
        }
    }
}

In Laravel, this replaces simple mutators on Eloquent models. Instead of defining getNameAttribute and setNameAttribute methods, you can define the hook directly on the property. The framework's attribute casting still works alongside hooks, so you can combine both for complex transformations. The hook runs first, then the cast is applied to the result.

Verify the behavior by running a simple test: create a model, set a value with extra whitespace, and assert the stored value is trimmed. The test will pass once the hook is active. You can also use the tinker artisan command to quickly test the hook in an interactive session.

How does asymmetric visibility work?

Asymmetric visibility lets you declare a property as publicly readable but privately (or protectedly) writable. This is useful for properties that should be set once during construction or by specific methods, but read freely. It provides more flexibility than the existing readonly keyword.

class Order
{
    public private(set) string $status;

    public function __construct(string $initialStatus)
    {
        $this->status = $initialStatus;
    }

    public function markAsShipped(): void
    {
        $this->status = 'shipped';
    }
}

This pattern is common in value objects and domain models within Laravel. It prevents accidental mutation from outside the class while keeping the property accessible for reading in views or API resources. The private(set) modifier is the key part of the syntax. You can also use protected(set) to allow child classes to modify the property.

A common failure mode is forgetting that the setter runs on assignment. If you have validation logic in the setter, it will execute every time the property is assigned, including in the constructor. This is usually the desired behavior, but it can cause unexpected exceptions if the constructor passes an invalid value.

What is the PHP pipe operator?

The pipe operator (|>) passes the result of the left-hand expression as the first argument to the right-hand function or callable. It creates a left-to-right data flow that is easier to read than nested function calls. This operator is inspired by functional programming languages and brings a new way to compose logic in PHP.

$cleanName = $rawInput
    |> trim(...)
    |> mb_strtolower(...)
    |> fn($s) => preg_replace('/[^a-z0-9]/', '', $s);

In Laravel, you can use this in collections, custom pipelines, or data transformation steps in a job. The operator works with any callable, including static methods and closures. It does not change how collections work, but it gives you another tool for composing logic. The ... syntax is used to pass the argument by name, which is required for some built-in functions.

How do these features affect Laravel codebases?

The impact is gradual. You can adopt these features file by file without breaking existing code. Here is a practical comparison of the old and new patterns.

PatternBefore PHP 8.5After PHP 8.5
Simple property mutationEloquent mutator methodsProperty hooks on the model
Immutable public statePrivate property + getter methodAsymmetric visibility
Data transformationNested function callsPipe operator chain

The pipe operator is particularly useful in Laravel Jobs where you process a payload through several steps. Instead of a long method with intermediate variables, you can create a clear pipeline. This makes the job's logic easier to follow and test. You can also use it in form request classes to validate and transform input in a single, readable flow.

When adopting property hooks in Eloquent models, be aware that the framework's attribute casting runs after the hook. If your hook trims a string, the cast will then process the trimmed value. Test the interaction to ensure the final stored value is correct. This is a common source of subtle bugs during migration.

What should you verify before upgrading?

First, check your hosting environment for PHP 8.5 support. Use the php -v command on your server or local machine. Second, run your test suite against PHP 8.5 to catch any deprecation warnings or breaking changes. Third, review any use of readonly properties, as asymmetric visibility provides a more flexible alternative in some cases.

The official migration guide on php.net lists all changes. For Laravel-specific compatibility, check the framework's release notes. The Laravel Octane on PHP 8.5 post covers performance implications for long-running processes like Octane.

Will property hooks replace all Eloquent accessors?

No. Property hooks are for simple, direct property access. Eloquent accessors and mutators handle more complex logic, including interacting with other attributes or the database. Use hooks for straightforward transformations and keep accessors for logic that needs the full model context. You can also use hooks with the Illuminate\Database\Eloquent\Concerns\HasAttributes trait if you need to interact with the attribute system.

Can I use the pipe operator with Laravel collections?

Yes, but it does not replace the collection API. The pipe operator works with individual values and callables. For transforming a collection, use the collection methods like map, filter, and reduce. You can use the pipe operator inside those methods if you need to compose a transformation function. The operator is most useful for scalar data processing.

Is asymmetric visibility the same as readonly properties?

No. A readonly property can only be set once, typically in the constructor. Asymmetric visibility allows the property to be set multiple times, but only from within the class or by specific visibility modifiers. Use readonly for truly immutable state and asymmetric visibility for controlled mutability. The performance characteristics are similar, so choose based on semantics.

DD

David Dew Mallick

Software Engineer

I build AI-driven SaaS infrastructure and backend systems with Laravel, AWS, and SQL, and write about the engineering decisions behind them.

GitHubLinkedInEmail

More posts

  • Sep 28, 2026 · 6 min read

    Laravel Testing: Why 1,800 Passing Tests Still Ship Bugs

    Laravel testing that passes in CI can still ship real bugs. Learn where test suites lie and how to close the gap between green tests and working software.

  • Sep 27, 2026 · 5 min read

    Laravel Octane on PHP 8.5: What Changes

    PHP 8.5 changes what Laravel Octane can offer and what it can break. Here is what the pipe operator means for Octane apps and how to avoid state leaks.

On this page

  • What are PHP property hooks?
  • How does asymmetric visibility work?
  • What is the PHP pipe operator?
  • How do these features affect Laravel codebases?
  • What should you verify before upgrading?
  • Will property hooks replace all Eloquent accessors?
  • Can I use the pipe operator with Laravel collections?
  • Is asymmetric visibility the same as readonly properties?
Back to top

End of record

Back to top↑

David Dew Mallick

Dhaka, Bangladesh

Contact

  • david.dew.mallick@g.bracu.ac.bd
  • GitHub
  • LinkedIn

2026 David Dew Mallick

  • Privacy
  • Terms
  • Cookies