top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is Final Class in PHP?

0 votes
79 views
What is Final Class in PHP?
posted Jul 1, 2014 by Amanpreet Kaur

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Final class is a class that can never be inherited.It protects the methods of class to be overriden by the child classes.
e.g.

final class baseclass
{
public function mymethod()
{
echo "baseclass method";
}
}
class derivedclass extends baseclass
{
public function mymethod()
{
echo "derivedclass method";
}
}
$c= new derivedclass();
$c->mymethod();

In the above example base class is declared as final and hence can not be inherited.
The compiler will give error for this example as deriveclass is trying here to inherit baseclass.

answer Jul 2, 2014 by Mohit Sharma
Similar Questions
0 votes

I have a question about using a php user class and session variables. Let's say that I have managed to create a user class that finds a particular person from the database query.

As I move about the site from page to page it would be nice to be able to use the current user inside the user class without needing to re – look them up in the database multiple times

Q: so is there a way to combine the current active user in the class with session variables so that they can be used multiple times? If so, how would this work?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...