When to use Final in PHP

0 votes

Although I am aware of what a final class is, I am curious about how and when it is actually necessary.

<?php
final class Foo extends Bar
{
   public function()
   {
     echo 'John Doe';
   }
}

If I've got it right, "final" allows it to extend "Foo.".

Can somebody tell me when and why to use the word "final"? I.e., is there any justification for not extending a class?

It would be useful to construct a class that extends "Bar" if, for instance, classes "Foo" and "Bar" are missing some features.

Jul 24, 2022 in PHP by Kithuzzz
• 38,000 points
370 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,840 points
1,149 views
0 votes
2 answers

How to use basic authorization in PHP curl?

If you are saying Basic authentication, then ...READ MORE

answered Jan 3, 2021 in PHP by Manas
• 140 points
36,434 views
0 votes
0 answers

when to use index.php instead of index.html

I wanted to know when do I ...READ MORE

May 30, 2022 in PHP by Kichu
• 19,040 points
665 views
0 votes
0 answers

How to efficiently use try...catch blocks in PHP

I was using try..catch blocks in my ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
611 views
0 votes
0 answers
0 votes
0 answers

Is it possible to write strictly typed PHP code?

Is it possible to write code like ...READ MORE

Jun 6, 2022 in PHP by Kichu
• 19,040 points
371 views
0 votes
0 answers

What does the variable $this mean in PHP?

Can someone please explain how the variable ...READ MORE

Jun 11, 2022 in PHP by narikkadan
• 63,600 points
568 views
0 votes
0 answers

What is the difference between public, private, and protected?

When and why should I use public, ...READ MORE

Jun 16, 2022 in PHP by narikkadan
• 63,600 points
453 views
0 votes
0 answers

Advantages and Disadvantages of Inheritance in php

Could someone please explain the main benefits ...READ MORE

Jul 28, 2022 in PHP by Kithuzzz
• 38,000 points
639 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP