MyBB Community Forums

Full Version: PHP Class not found when it's there
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In one of my plugins I have a very small class defined at the bottom of the file. However, someone's reported that they get an error saying this class doesn't exist, even though it's in their copy of the file, and seems to work properly for everybody else, me included.

What could cause this to happen?? In case you don't know, a function or class doesn't have to be defined earlier in the script than when it's used, it can be defined/included anywhere and it'll work. Basically, the code is this:

<?php
// lots of code
$object = new MyClass();
// lots of code
class MyClass extends Class
{

}
?>

Anyone have any ideas??
is the class part of an already included file or does it need to be included at the time the object is created?

edit: i should clarify. I know how classes work, i am asking if your class has its own file and thus needs the include/require once before trying to create the new object
It's all part of one flat file. It's part of the admin module file of this: http://mods.mybb.com/view/plugin-uploader The class is defined on line 1173, used on line 197.

I may be missing something obvious, but I can't reproduce the error and AFAIK it's not happened to anybody else, just one person, and the class should always be available.
Crappy PHP version? Only thing i can think of that affects some and not others Confused
That's the only explanation I can think of too, but it'll have to be 5.1+ as 1.6 is being used, and I would be surprised if a newer PHP version changed the way this sort of thing worked.
While it makes no difference, just to troubleshoot it you could try putting the class at the beginning of the file?