Here’s a tip for Laravel developers. In PHP 8.2, you can use the #[\SensitiveParameter] attribute to mark sensitive parameters in your Eloquent model methods. This is useful for protecting sensitive data in stack traces. For example:

class User extends Model
{
    public function updatePassword(#[\SensitiveParameter] string $newPassword)
    {
        // https://laravel.com/docs/11.x/hashing#hashing-passwords
        $this->password = Hash::make($newPassword);
        $this->save();
    }
}

If an exception occurs in this method, PHP will replace the $newPassword value with Object(SensitiveParameterValue) in any stack traces, helping to prevent accidental exposure of sensitive information.

This can be particularly useful when working with sensitive data like financial transactions, personal information, and passwords in your Laravel ORM models.

Links

https://www.php.net/manual/en/class.sensitiveparameter.php


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Involved & Explore More

an abstract painting with blue and yellow colors

Catch up on what I’ve been writing lately.

Show your gratitude.

Join Dare To Code Email List

Get emails from me on full-stack PHP development by subscribing to the Dare To Code mailing list.