Final Keyword

  • In PHP, Final keyword is applicable to only class and class methods. We cannot declare as Final in PHP.
  • So if we declare class method as a Final then that method cannot be override by the child class.
  • Same as method if we declare class as a Final then that class cannot be extended any more.

Example 1

snippet
<?php
	
	class base
	{
		final public function dis1()
		{
			echo "Base class..";
		}	
	}
	class derived extends base
	{
		public function dis1()
		{
			echo "derived class";
		}
	}
	$obj = new derived();
	$obj->dis1();

?>

Output:

Final Keyword
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +