1

I don't get why I get this error

Fatal error: Class 'ImageJpg' not found 

Here is the code that I use

spl_autoload_register(function($class) { if(file_exists($class)) { include $class.'.php'; } }); $n = new ImageJpg(); 

File ImageJpg.php is in the same dir with the code above.

Here is the content of ImageJpg.php

<?php class ImageJpg { public function __construct() { echo 'Image from jpg called'; } } 

3 Answers 3

2
if(file_exists($class)) { include $class.'.php'; } 

Should be

if(file_exists($class.'.php')) { include $class.'.php'; } 
Sign up to request clarification or add additional context in comments.

Comments

0

Is there a class named ImageJpg in your ImageJpg.php file? And does file exist? Try this:

spl_autoload_register(function($class) { if(file_exists($class.'.php')) { include $class.'.php'; if (!class_exists($class)) { die('required class not present'); } } else { die('file not found'); } }); 

1 Comment

I see now. So the problem must have been the one xdazz pointed out (and I fixed that in my code).
0

I had issues with file_exists also and I was debugging for like 2 hours and nothing happen even after I've searched all around and also on web. At the end it was a typo: instead userController.php it was userControlller.php the actual file. Check again (in this order):

  1. Make SURE you don't have typo in your file name (either PHP or file system)
  2. Check your path - ROOT and/or use getcwd()
  3. Temporary print / log your checks to make sure everything matches
  4. Avoid human error :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.