0

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
  • You're certain that you're including the correct users.class.php? Commented Oct 28, 2010 at 2:10

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
I feel awfully stupid, I spent over an hour working at a typo. My problem was I required the wrong file.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.