Final Methods in PHP5

Final Methods in PHP5

The function declared as final can be used with in subclass but
like other function we cannot override the function declared as final.

<?php

class A {

final function print_all() {
echo ‘this is class A’;
}

}

class B extends A {

function print_all() {
echo ‘this is class B’;
}

}

$obj = new B();
$obj->print_all();

?>

Executing the above example results in the following error:

Fatal error: Cannot override final method A::print_all() in E:/work/test_final.php

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.