Jump to content

Recommended Posts

I have the class called "date_sys" and it is saved in the file date.php Now I have the file called session.php which includes date.php (they are the in the same directory).

 

date_sys class:

 

<?php

class date_sys
{
    static function breakdown_int_timestamp ($timestamp)
    {
        $datestamp[0] = substr ($timestamp, 0, 4);
        $datestamp[1] = substr ($timestamp, 4, 2);
        $datestamp[2] = substr ($timestamp, 6, 2);
        $datestamp[3] = substr ($timestamp, 8, 2);
        $datestamp[4] = substr ($timestamp, 10, 2);
        $datestamp[5] = substr ($timestamp, 12, 2);
        
        return $datestamp;
    }
    
    static function month_from_int ($int)
    {
        $int = (int) $int;
        $months = array ("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
        return $months[$int];
    }
}

?>

 

Now in the session.php file right after I include the file I go:

 

<?php

include "date.php";

die(date_sys::month_from_int (4));

?>

And I'm getting: Fatal error: Class 'date_sys' not found in D:\xampp\htdocs\scm\core\session.php on line 12

 

[Edit] Here's something interesting. The errors occurs on my computer (Windows XP) but not on my Server (Ubuntu Server 7.10). Perhaps something in the php.ini file?

Link to comment
https://forums.phpfreaks.com/topic/84303-cannot-find-class-that-was-just-included/
Share on other sites

I found this in the php.ini file:

 

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = ".:\xampp\php\pear\"

 

Is this what you're referring to?

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = "/" <- Is that correct?

 

But what's weird is that session.php includes other files. (sql.php, cookie.php plus others) and it's just fine. Why does iit not like my date_sys class?

Check your web server log for errors to find out what is really happening.

 

The include_path is probably at fault. Why other include files work (perhaps they are working because they are getting included elsewhere) is any bodies guess.

 

Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in the current working directory.

 

Based on that, perhaps you have more than one date.php file and the wrong one is getting found due to the include_path searches and the CWD.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.