php5 calling class problem
Results 1 to 5 of 5

Thread: php5 calling class problem

  1. #1
    Senior Member
    Join Date
    Jan 2002

    php5 calling class problem

    Hi guys,

    I have a strange problem. I use several classes like, etc. For security reasons I've changed the names to user.php, db.php etc. Problem is, that now the script doesn't work a I only get this message: Fatal error: Class 'User' not found in /var/www/htdocs/pracovni/SVV/svv.php on line 4

    All files all correctly required. But it seems like no class is defined... Any ideas?


  2. #2
    Senior Member
    Join Date
    Nov 2001
    A couple of possibilities immediately spring to mind:
    - Your require()s are done in the wrong order, so one of your included/required scripts tries to instantiate a User class object before the definition exists.
    - You have multiple requires that re-define the "User" class, and could break things. For this, look at using require_once instead of require.

    Without seeing relevant parts to your code, I doubt anyone is going to be able to reliably troubleshoot it, so you're on your own there if you want to keep the code to yourself.

    You can troubleshoot it step by step by printing out the errors and exiting out of the script using:

    You might have a line like:
    PHP Code:
    if (! 
    class_exists('User')) die ("User class could not be found.");
    // Then try to instantiate the class
    $userObj = new User(); 
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?

  3. #3
    Senior Member
    Join Date
    Jan 2002


    Thank you for your answer.

    I think I can be almost 100% sure, that my requires are done in right order. Because if required files has extension .inc everything works fine. But when I change this extension to .php I get error message. Also the code should be ok, because everything worked ok before changing to .php extension.

    Right now I also found this - i tried to add

    AddType application/x-httpd-php .inc to my mod_php.conf

    so I can leave my classess with .inc and noone can read them as text files. After done so, I get the error message also for .inc files. Strange, isn't it?)

    last info: - if I copy my classes directly into main php code, everything works fine...

    editProblem solved. I don't know why, but it looks like the problem was in the absolute path.

    If I use require_once "" everything works.
    If I use require_once "" problem occures.
    If I use require_once "./class/databaze.php" everything works fine.

    If this makes sence I don't want to be sober)


  4. #4
    Senior Member
    Join Date
    Mar 2004

    Just a very stupid guess, but I had to work hard the last few days, so nothing else
    might pop out of my head

    Might it be possible that if you require,
    php actually processes databaze.php before sending its content to the your php-script,
    that does the "require"ment?
    Which means, that it might end up empty, so no class actually is declared and defined
    which you can instantiate, hence an error occurs?

    ...while using the "local" file, no php-processing is applied ?

    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  5. #5
    Senior Member
    Join Date
    Jan 2002
    sec_ware - Yes you are absolutly right and I'm a complete idiot. That was a huge mistake to call class with http. Sorry guys for bothering you, but I have always the biggest problems with these kind of things...


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts