Source: programmingdive.com

What is use of final keyword in PHP?

Category: PHP

Well, in programming also it means the same.

Let’s explore use of final keyword in PHP in depth.

When we need to use final keyword to class then we just need to prefix class name with final keyword and for a method as well we need to do the same step by prefixing method name as final.

In the above examples, we first defined class classA as final which means now all the properties and methods are final and in the second example methodA is final which means now only methodA is final.

PHPs object oriented is quite late but we need to keep in mind that we can make class as a final whenever we feel that this class should never be extended.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners