1

I have a problem with the extends of PHP. My code in the page.class.php:

    <?php
    require_once ('globals.class.php');
    require_once ('Smarty.class.php');

    class CPage extends Smarty
    {
     .
     .
     .

In the Smarty.class.php the class name is Smarty.

So I don't know why I get this error:

Fatal error: Class 'Smarty' not found in C:\xampp\htdocs\blog\www\classes\page.class.php on line 6

hakre
  • 193,403
  • 52
  • 435
  • 836
  • are you sure `Smarty.class.php` is not empty ? – Mihai Iorga Sep 19 '12 at 06:39
  • if Smarty uses namespace, you should declare class CPage extends \namespace\of\Smarty – Alain Tiemblo Sep 19 '12 at 06:40
  • Can you do a `echo (defined('SMARTY_DIR') ? 'Yes' : 'No');` to see if Smarty.class.php is being processed correctly? No reason why hte code should fail unless the require_once isn't being called, or is callign the "wrong" file (e.g. as Mihai said, an empty file). – Robbie Sep 19 '12 at 07:11
  • echo (defined('SMARTY_DIR') ? 'Yes' : 'No'); -> answer is 'No' .. The Smarty.class.php isn't empty, the class will define there 100%. I think the answer should be 'Yes' @Robbie or? What's wrong?! :/ – Alexander Kante Sep 19 '12 at 08:49

1 Answers1

0

This is more a comment than an actual answer:

As you use require I assume that the Smarty class has been defined.

So you are probably using namespaces, which would require you to use that specific class or provide a fully qualified classname (FQCN) instead:

class CPage extends \Smarty
                    ^- Smarty is in the global namespace in this example

Otherwise use the class on top:

Use \Smarty;

to import it into your current namespace.

The answer is with the pre-condition that the Smarty class you refer to is in the global namespace. I'm not fluent with Smarty so I do not know if it has it's own namespace yet, and if so, which one it is. So the concrete FQCN might vary.

See as well:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836