DEV Community

Cover image for ReadOnly properties with PHP 8.1 🐘
Pierre-Henry Soria ✨
Pierre-Henry Soria ✨

Posted on • Edited on

ReadOnly properties with PHP 8.1 🐘

Today, let's learn how you can efficiently use the new keyword readonly introduced by PHP 8.1 🐘

By declaring class properties β€œreadonly”, the properties will only be allowed to be initialized once. Any further attempts to give another value will throw an error as it won’t be allowed.

To go further, my Udemy course teaches how to build a complete PHP 8 application from scratch. Available at https://www.udemy.com/course/create-real-world-php-webapp-from-scratch/

Top comments (0)