tags:

views:

22

answers:

2

I'm getting this really bad error. I tried copying the example classes off PHP.net. The class worked but I cant seem to get it to include right. My index file includes the users.class.php and then the content.php which has the call to the class.

Error:

Fatal error: Class 'A' not found in X:\xxxxx\xxxx\xxxxx\content.php on line 2

index.php:

<?php
   require('users.class.php');
   $a = new A();
   require('content.php');
?>

content.php:

<?php
   echo $a->foo();
?>

users.class.php:

<?php
   class A
   {
      function foo()
      {
         return 'hello world';
      }
   }
?>
+1  A: 

hmm... my guess is that the line

echo $a->foo();

is being executed before the preprocessor has fully read in users.class.php.

try adding this line to content.php:

require_once("users.class.php");

above the echo... line.

Also, change your index.php require to require_once as well. This will ensure that your class is read in before code is executed, and you won't get any errors saying that the file has already been included.

Brian Driscoll
mmm.. that make no sense. the code is blocking, in the same sense on js on the browsers, also by definition a *require* or *include* statement will just "paste" (include) the code just before continue the execution
Gabriel Sosa
I feel awfully stupid, I spent over an hour working at a typo. My problem was I required the wrong file.
Lienau
A: 

first: I ran your code and works

second: the error make no sense since content.php doesn't not contains the declaration of the class "A", in any case the error it should say that the class was not found in the "index.php" file.

Please check for hidden chars and try again

Gabriel Sosa