Teknomers | Dünyadan Güncel Teknoloji | Oyun | Müzik | Film | Spor HaberleriTeknomers | Dünyadan Güncel Teknoloji | Oyun | Müzik | Film | Spor HaberleriTeknomers | Dünyadan Güncel Teknoloji | Oyun | Müzik | Film | Spor Haberleri
Yazı Tipi BoyutlandırıcıAa
  • Anasayfa
  • Teknoloji
    • Siber Güvenlik
    • Yapay Zeka
    • Donanım
    • Bilim
  • Yazılım
  • Savunma & İstihbarat
  • Oyun
  • Yaşam
    • Finans
    • Sinema
    • Dünyadan Haberler
  • İş Birliği
Okuma: Laravel Uygulamanızda Muhtemelen Henüz Kullanmadığınız PHP 8.4 Özellikleri
Paylaş
Yazı Tipi BoyutlandırıcıAa
Teknomers | Dünyadan Güncel Teknoloji | Oyun | Müzik | Film | Spor HaberleriTeknomers | Dünyadan Güncel Teknoloji | Oyun | Müzik | Film | Spor Haberleri
Ara
Bizi Takip Et
  • Hakkımızda
  • Gizlilik politikası
  • Tanıtım Yazısı ve Backlink Hizmeti
© 2026 Teknomers. All Rights Reserved.

Anasayfa » Laravel Uygulamanızda Muhtemelen Henüz Kullanmadığınız PHP 8.4 Özellikleri

Yazılım

Laravel Uygulamanızda Muhtemelen Henüz Kullanmadığınız PHP 8.4 Özellikleri

teknomers
Son güncelleme: 8 Mayıs 2026 08:46
teknomers
Paylaş
Paylaş

Originally published at hafiz.dev


If you followed the Laravel 13 upgrade path, you’re running PHP 8.4 by now (or you should be, since Laravel 13.3+ pulls in Symfony 8 components that require it). The upgrade guide covers the migration steps, but upgrading your runtime and actually using the new language features are two different things.

<p>Most Laravel developers upgrade PHP, confirm their tests pass, and keep writing the same PHP 8.1-style code they've always written. That works, but you're leaving real improvements on the table. PHP 8.4 shipped six features that directly clean up the kind of code you write in a Laravel app every day.</p>

<h2>
    <a name="1-property-hooks-replace-your-getters-and-setters" href="#1-property-hooks-replace-your-getters-and-setters"></a>
    1. Property Hooks: Replace Your Getters and Setters
</h2>

<p>Property hooks let you define <code>get</code> and <code>set</code> behavior directly on a class property. No more writing separate getter and setter methods for simple transformations.</p>

<p><strong>Before (PHP 8.3):</strong><br/></p>
<div class="highlight js-code-highlight">
    <pre class="highlight php"><code>

class PriceCalculator
{
private float $priceInCents;

public function getPriceInCents(): float
{
    return $this->priceInCents;
}

public function setPriceInCents(float $value): void
{
    if ($value < 0) {
        throw new \InvalidArgumentException('Price cannot be negative.');
    }
    $this->priceInCents = $value;
}

public function getPriceInDollars(): float
{
    return $this->priceInCents / 100;
}

}

<p><strong>After (PHP 8.4):</strong><br/></p>
<div class="highlight js-code-highlight">
    <pre class="highlight php"><code>

class PriceCalculator
{
public float $priceInCents {
set {
if ($value < 0) {
throw new \InvalidArgumentException(‘Price cannot be negative.’);
}
$this->priceInCents = $value;
}
}

Contents
  • 5. Method Chaining on new Without Parentheses
  • 6. Multibyte String Functions: trim, ltrim, rtrim
  • When to Start Using These
  • FAQ
    • Do property hooks work with Eloquent models?
    • Can I use asymmetric visibility with constructor promotion?
    • Do I need to upgrade PHPStan or Larastan for PHP 8.4 features?
    • What’s the minimum PHP 8.4 version I should run?
  • What’s Next
public float $priceInDollars {
    get => $this->priceInCents / 100;
}

}

<p>The <code>$priceInDollars</code> property is virtual. It doesn't store anything. It computes the value on read from <code>$priceInCents</code>. And the <code>set</code> hook on <code>$priceInCents</code> validates the input without a separate method.</p>

<p>Where this shines in Laravel: service classes, value objects, and DTOs where you'd normally write getters with transformation logic. Note that Eloquent models have their own accessor/mutator system via <code>Attribute::make()</code>, so property hooks don't replace those directly. But for any non-Eloquent class in your app (and you should have plenty), property hooks remove a lot of boilerplate.</p>

<h2>
    <a name="2-asymmetric-visibility-public-read-private-write" href="#2-asymmetric-visibility-public-read-private-write"></a>
    2. Asymmetric Visibility: Public Read, Private Write
</h2>

<p>Before PHP 8.4, if you wanted a property that anyone could read but only the class itself could modify, you had two options: make it private and add a getter, or make it <code>readonly</code>. Both had tradeoffs. <code>readonly</code> can only be set once, which doesn't work if the value changes over the object's lifetime.</p>

<p>Asymmetric visibility solves this cleanly:</p>

<p><strong>Before (PHP 8.3):</strong><br/></p>
<div class="highlight js-code-highlight">
    <pre class="highlight php"><code>

class OrderStatus
{
private string $status = ‘pending’;

public function getStatus(): string
{
    return $this->status;
}

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

}

// Usage
$order->getStatus(); // ‘pending’

<p><strong>After (PHP 8.4):</strong><br/></p>
<div class="highlight js-code-highlight">
    <pre class="highlight php"><code>

class OrderStatus
{
public private(set) string $status = ‘pending’;

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

}

// Usage
$order->status; // ‘pending’ – direct access, no getter needed
$order->status = ‘cancelled’; // Error: Cannot modify private(set) property

<p>The <code>public private(set)</code> declaration means: anyone can read <code>$status</code> directly, but only the class itself can change it. No getter needed. No <code>readonly</code> restriction. The value can change internally through methods like <code>markAsShipped()</code>, but external code can't tamper with it.</p>

<p>This is ideal for data transfer objects in your Laravel app. API response DTOs (especially if you're following <a href="https://hafiz.dev/blog/laravel-api-development-restful-best-practices" target="_blank" rel="noopener noreferrer">REST API best practices</a>), configuration objects, form data objects. Anywhere you want external code to read properties directly without letting them modify the state.</p>

<p>You can also use <code>public protected(set)</code> to allow child classes to modify the property while keeping external write access restricted.</p>

<h2>
    <a name="3-arrayfind-stop-filtering-when-you-only-need-one" href="#3-arrayfind-stop-filtering-when-you-only-need-one"></a>
    3. array_find(): Stop Filtering When You Only Need One
</h2>

<p>PHP has had <code>array_filter()</code> forever, but if you only need the first element that matches a condition, you've been writing this:</p>

<p><strong>Before (PHP 8.3):</strong><br/></p>
<div class="highlight js-code-highlight">
    <pre class="highlight php"><code>

$users = [
[‘name’ => ‘Alice’, ‘role’ => ‘admin’],
[‘name’ => ‘Bob’, ‘role’ => ‘editor’],
[‘name’ => ‘Charlie’, ‘role’ => ‘admin’],
];

$firstAdmin = array_values(array_filter(
$users,
fn($user) => $user[‘role’] === ‘admin’
))[0] ?? null;

<p>That's ugly. <code>array_filter</code> processes the entire array, <code>array_values</code> re-indexes it, and the <code>[0] ?? null</code> handles the empty case. Three operations for something that should be one line.</p>

<p><strong>After (PHP 8.4):</strong><br/></p>
<div class="highlight js-code-highlight">
    <pre class="highlight php"><code>

$firstAdmin = array_find($users, fn($user) => $user[‘role’] === ‘admin’);

<p><code>array_find()</code> returns the first matching element and stops iterating. No re-indexing, no null coalescing. If nothing matches, it returns <code>null</code>.</p>

<p>PHP 8.4 also adds three related functions:</p>
<ul>
    <li><code>array_find_key()</code> returns the key of the first match instead of the value</li>
    <li><code>array_any()</code> returns <code>true</code> if at least one element matches (like <code>Collection::contains()</code> for arrays)</li>
    <li><code>array_all()</code> returns <code>true</code> if every element matches (like <code>Collection::every()</code> for arrays)</li>
</ul>

<p>In Laravel, you'll mostly use these in places where you're working with raw arrays instead of collections: config processing, middleware logic, job payloads, or anywhere performance matters and you don't want to create a Collection instance just to call <code>-&gt;first()</code>.</p>

<h2>
    <a name="4-the-deprecated-attribute" href="#4-the-deprecated-attribute"></a>
    4. The #[\Deprecated] Attribute
</h2>

<p>PHP has always had a way to deprecate built-in functions, but there was no native mechanism for marking your own functions, methods, or class constants as deprecated. You'd either put a <code>@deprecated</code> docblock comment (which only IDE-level tools read) or throw a manual <code>trigger_error()</code>.</p>

<p><strong>Before (PHP 8.3):</strong><br/></p>
<div class="highlight js-code-highlight">
    <pre class="highlight php"><code>

/ 

  • @deprecated Use calculateTotal() instead
    */
    function calculateSubtotal(array $items): float
    {
    trigger_error(‘calculateSubtotal() is deprecated, use calculateTotal()’, E_USER_DEPRECATED);
    return calculateTotal($items);
    }

    After (PHP 8.4):

    
    #[\Deprecated(message: 'Use calculateTotal() instead', since: '2.0')]
    function calculateSubtotal(array $items): float
    {
     return calculateTotal($items);
    }
         

    The #[\Deprecated] attribute triggers a real E_USER_DEPRECATED notice when the function is called. IDEs like PhpStorm show it with a strikethrough. Static analysis tools like PHPStan and Larastan flag it automatically. And you get a since parameter to track when the deprecation started.

    Where this helps in Laravel: if you maintain internal packages, APIs with versioned endpoints, or shared service classes across teams, this is a cleaner way to signal “stop using this” than a docblock that nobody reads.


    5. Method Chaining on new Without Parentheses

    A small quality-of-life improvement that removes an annoying syntax limitation:

    Before (PHP 8.3):

    
    $date = (new DateTime())->format('Y-m-d');
    $response = (new JsonResponse($data))->setStatusCode(201);
         

    Those extra parentheses around new ClassName() were required to chain a method call. They look awkward and trip up developers who forget them.

    After (PHP 8.4):

    
    $date = new DateTime()->format('Y-m-d');
    $response = new JsonResponse($data)->setStatusCode(201);
         

    No wrapping parentheses needed. You can also access properties directly: new Foo()->bar. This is a small change, but it cleans up code in places where you create and immediately use throwaway objects, which happens often in tests, seeders, and one-off scripts.


    6. Multibyte String Functions: trim, ltrim, rtrim

    PHP finally has multibyte-aware trim functions. If your app handles content in languages like Japanese, Chinese, Arabic, or Korean, you’ve probably been using workarounds with preg_replace to trim multibyte whitespace characters that trim() ignores.

    Before (PHP 8.3):

    
    // Standard trim doesn't handle multibyte whitespace like \u{3000} (ideographic space)
    $cleaned = preg_replace('/^\s+|\s+$/u', '', $input);
         

    After (PHP 8.4):

    
    $cleaned = mb_trim($input);
         

    PHP 8.4 adds mb_trim(), mb_ltrim(), and mb_rtrim(). If your Laravel app processes user input from a multilingual audience, these are a direct improvement. Use them in your form request prepareForValidation() methods or in custom Eloquent casts where you clean input before storage.


    When to Start Using These

    You don’t need to refactor your entire codebase. The practical approach:

    Use immediately in new code. When you write a new service class, DTO, or value object, use property hooks and asymmetric visibility instead of getters/setters. When you write a new array operation on raw data, reach for array_find() before array_filter().

    Refactor gradually. When you touch an existing class for a feature or bug fix, modernize it if it takes less than five minutes. Don’t create refactoring PRs that touch 50 files. That’s risk for no product value.

    Don’t touch Eloquent models. Eloquent has its own accessor/mutator system that doesn’t need property hooks. And asymmetric visibility conflicts with how Eloquent hydrates properties. Keep Eloquent models using Laravel’s patterns.


    FAQ


    Do property hooks work with Eloquent models?

    Not in the way you might expect. Eloquent uses dynamic property access via __get and __set, which doesn’t interact cleanly with PHP property hooks. Stick with Eloquent’s Attribute::make() for model accessors and mutators. Use property hooks in your service classes, DTOs, form data objects, and other non-Eloquent classes.


    Can I use asymmetric visibility with constructor promotion?

    Yes. public private(set) string $name works in constructor parameters:

    
    public function __construct(
     public private(set) string $name,
     public protected(set) int $age,
    ) {}
         

    This gives you a publicly readable, internally writable promoted property in one line.


    Do I need to upgrade PHPStan or Larastan for PHP 8.4 features?

    PHPStan 2.1+ fully supports property hooks, asymmetric visibility, and the #[\Deprecated] attribute. If you’re running an older version, upgrade before adopting these features, otherwise your CI pipeline will flag false positives. Larastan follows PHPStan’s version, so updating Larastan pulls in the PHP 8.4 support automatically.


    What’s the minimum PHP 8.4 version I should run?

    PHP 8.4.1 or later. The 8.4.0 release had a few edge-case bugs with property hooks in certain inheritance scenarios that were fixed in 8.4.1. If you’re deploying to production, start with the latest 8.4.x patch.


    What’s Next

    PHP 8.4 isn’t a small release. Property hooks and asymmetric visibility change how you structure classes in a fundamental way. The new array functions remove patterns you’ve been copy-pasting for years. And the #[\Deprecated] attribute gives you a tool that PHP itself has had forever but never shared with userland code.

    If you haven’t upgraded yet, the 4 composer conflicts post walks you through the blockers you’ll hit on the way to PHP 8.4 and Laravel 13. And if you’re building something with Laravel and want help modernizing your codebase for PHP 8.4, get in touch.

Kaynak: Orijinal Makale

SLA’lar Başarısız Olmaz, Kötü SLA Yönetimi Olur!
Contabo VPS Üzerinde Laravel Yayınlama: Adım Adım Kılavuz
Küçük Bir Denetim Aracının Büyük Bir Güvenlik Çerçevesinden Daha Avantajlı Olmasının Nedenleri (laravel-audit)
Laravel ile Prodüksiyon MCP Sunucusu Oluşturma
PHP Özellik Enfestasyonu (Gemini Tarafından)
Bu Makaleyi Paylaş
Facebook Bağlantıyı Kopyala Yazdır
Paylaş
Önceki Makale Doktorunuzun sizi hiç aramamasının nedeni nedir?
Sonraki Makale Canvas Hack: Yeni Bir Fidye Yazılımı Krizi Okulları Sarstı!

Sanal Medya

FacebookBeğen
452Takip Et
PinterestSabitle
237Takip Et

Son Eklenenler

Tanrıların İntikamı: God of War Laufey’de Sürpriz Karakterler Bekleniyor
Oyun
JMGO N3 Ultimate projektör, yeni taşınabilir 4K şampiyonu mu?
Liste
Laravel AI SDK ile ReAct Sohbet Ajanı Geliştirme
Yazılım
Final Fantasy Revelasyonu: Definitif Son Ama Yan Hikayelere Kapı Aralıyor
Oyun
Final Fantasy 7’de Bulut’u Kara Büyücüye Dönüştüren Yenilikçi Sistem
Oyun
Yenilenen Korku Hikayesi: Michael Myers Maskesi ve Bıçağını Buldu
Oyun
//

Siber güvenlik, yapay zeka ve savunma sanayiinden; finans ve sinema dünyasına uzanan geniş bir yelpaze. Teknomers; teknoloji, strateji ve yazılım dünyasını sade bir dille sizlerle buluşturuyor.

Kurumsal

  • Hakkımızda
  • Gizlilik politikası
  • Tanıtım Yazısı ve Backlink Hizmeti

Kategoriler

  • Teknoloji
  • Oyun
  • Sinema
  • Siber Güvenlik
  • Bilim
  • Finans
  • Dünyadan Güncel Haberler

Populer

  • TV'de Ücretsiz İzlenebilen Şifresiz Erotik Kanallar (2025 Güncel Frekans Listesi)

  • The Last of Us PC Kontrolleri: Hızlı Silah Değiştirme ve Tüm Tuşlar (2025)

  • Hogwarts Legacy'de Odaklanma İksiri Nasıl Yapılır?

Teknomers | Dünyadan Güncel Teknoloji | Oyun | Müzik | Film | Spor HaberleriTeknomers | Dünyadan Güncel Teknoloji | Oyun | Müzik | Film | Spor Haberleri
Bizi Takip Et
© 2026 Teknomers. All Rights Reserved.
Welcome Back!

Sign in to your account

Kullanıcı Adı veya E-posta Adresi
Şifre

Şifrenizi mi unuttunuz?