TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Function overwriting (http://www.talkphp.com/general/2357-function-overwriting.html)

Nor 02-27-2008 05:45 PM

Function overwriting
 
Is it possible(maybe in php future) that when you extend a class that you can disable function overwriting or does it apply to the final class php5 uses?

Code:

class x
{
  final function base()
  {
      echo 'main';
  }
}
class y extends x
{
  function base()
  {
      echo 'main2';
  }
}

will it error out or is it possible to stop the error and allow access to the root class without overwriting that function.

Code:

$cls = new y();
$cls->base();//would this output main?


Wildhoney 02-27-2008 06:37 PM

If the function in the parent didn't have the final keyword attached to it then it would echo out main2. However, as you've applied the final keyword, then a fatal PHP error will be evoked.

Quote:

Fatal error: Cannot override final method x::base() in C:\wamp\www\f.php on line 16


All times are GMT. The time now is 05:45 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0