Fatal error: Class Template may not inherit from final class (Base)

219 views
Skip to first unread message

David Foy

unread,
Aug 19, 2015, 11:21:07 PM8/19/15
to Fat-Free Framework
I hope this is an F3 question, and not an issue of my rudimentary grasp of class inheritance.
Let let me start by quoting the on-line PHP manual:

 
PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.(my emphasis)

Lines 43 of my version of base.php says:

final class Base extends Prefab implements ArrayAccess {... (emphasis mine)

I have experimented unsuccessfully with [echo Template::instance()->render('abc.htm'); ] 
and have never been able to make it work, the error message always being the same: 
Fatal error: Class Template may not inherit from final class (Base).
Yet other people make it work.
What am I missing here?

Ace

unread,
Aug 20, 2015, 2:20:32 AM8/20/15
to Fat-Free Framework
But Template extends Preview which extends View then Prefab?

Anatol Buchholz

unread,
Aug 20, 2015, 2:47:41 AM8/20/15
to Fat-Free Framework
mhhh … both are working for me:

$f3->route('GET /render',
   
function() {
    $a
= new Template;
        echo $a
->render('/app/tmpl/abc.htm');
   
}
);


$f3->route('GET /render',
   
function() {
        echo
Template::instance()->render('/app/tmpl/abc.htm');
   
}
);

can you provide more of your code?

Steve Cove

unread,
Aug 20, 2015, 4:23:41 AM8/20/15
to Fat-Free Framework
That is a strange error. The template class shipped with fatfree (lib/template.php):

https://github.com/bcosca/fatfree/blob/master/lib/template.php

Does not extend Base class.
Perhaps you have written your own class with the same name, that does?

The error message should give you the file path and line number.

xfra35

unread,
Aug 20, 2015, 5:21:37 AM8/20/15
to Fat-Free Framework
Either you have written your own class with the same name, or you're using a very old version of the Template class. Template used to extend Base in v2...

David Foy

unread,
Aug 20, 2015, 11:36:07 AM8/20/15
to Fat-Free Framework
Thanks for replying. I must be using an old version. I've been downloading and working with several old demo programs and have probably gotten the wrong version mixed in there.

David Foy

unread,
Aug 20, 2015, 11:47:00 AM8/20/15
to Fat-Free Framework
Thanks for your help. My template class had the 2013 copyright date and is completely different from the one I downloaded and installed a few minutes ago.

Steve Cove

unread,
Aug 20, 2015, 12:02:11 PM8/20/15
to Fat-Free Framework
Probably best to download a fresh copy of the current framework, and move all the other stuff into an archieve folder (or just delete it) - mixing code from different versions is going to cause issues.

Version 3 is a major change from version 2 - any version 2 code is not going to be much help, even for learning, because the changes are so great.

Unrelated, but what program do you use to write your code? A decent IDE would catch all sorts of syntax and logic errors (like the variable scope issues in your other post) and even provide code completion hints.
PhpStorm is my personal favourite, but its not free. Netbeans is probably the best free alternative, and many times better than a normal text editor, especially when you are learning.

David Foy

unread,
Aug 21, 2015, 12:57:20 PM8/21/15
to Fat-Free Framework
Thanks, Steve. I did just that. I'm still at the stage where I learn primarily from working code examples. They're the skeletons that I use,  and I created a lot of problems for myself because of that. I have a copy of PhpStorm but constantly fight with configuration issues, so in order to lower the learning curve I'm using a simpler tool called WeBuilder that catches syntax and I benefit from the utterly simple previews, but it may be time to try PhpStorm again. 
Reply all
Reply to author
Forward
0 new messages