SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whats wrong with this code

    Take a look at the code below:
    PHP Code:
    require_once("extension.inc");
    $this->php_ex=$php_ex
    echo 
    "$php_ex<p>\n";
    echo 
    "$this->php_ex<p>\n";
    require_once(
    'config.inc' $this->php_ex);
    require_once(
    "db.inc" .$this->php_ex); 
    This code is part of my class. I first include the file "extension.inc" and get the value of $php_ex. Then I assign this value to the class variable php_ex (so I can use it in other functions of the class without having to include extension.inc again). At the time the value of $php_ex is ".php". However whenever I try to run the script I get the following output:
    .php


    .php




    Warning: aoseo(config.inc) [function.aoseo]: failed to create stream: No such file or directory in ********.php on line 47

    Fatal error: aoseo() [function.aoseo]: Failed opening required 'config.inc' (include_path='.;c:\php4\pear') in ********.php on line 47
    What am I doing wrong here? I've double checked that config.inc.php exists in the same directory as this script. But as you can see it tries to include "config.inc" and not "config.inc.php" although $php_ex holds ".php".

    Edit: I've bleeped out the script name and path above on purpose.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't spread class definitions across multiple files. You might have to include the extension file outside the class, then pass the value of php_ex to the class function that will use it as a parameter.

    So something like:
    PHP Code:
    include(extension.inc);
    include(
    class_definition.inc);
    $obj = new class_definition;
    $obj->extension_handler($php_ex); 

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uh, looking at the error codes a little more carefully now, another problem (and perhaps the one actually throwing the errors here) is that your includes are outside the include path. So, you might have to move the files into your system's base include path folder, or define an additional include path via ini_set("include_path", ":extra path here").

  4. #4
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by k0ng
    You can't spread class definitions across multiple files. You might have to include the extension file outside the class, then pass the value of php_ex to the class function that will use it as a parameter.

    So something like:
    PHP Code:
    include(extension.inc);
    include(
    class_definition.inc);
    $obj = new class_definition;
    $obj->extension_handler($php_ex); 
    Yea, but the code I posted is from the original class_definition.inc. Hence the code should work. Also, when I do :
    PHP Code:
    require_once('config.inc' $this->php_ex); 
    for some reason it tries to include "config.inc" but misses out the .php part which is the value of $this->php_ex. The variable contains the value for sure because when I echo its value right one line before I try to include the file it echoes the right value. How can I make it include config.inc.php and not just config.inc?

  5. #5
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by k0ng
    Uh, looking at the error codes a little more carefully now, another problem (and perhaps the one actually throwing the errors here) is that your includes are outside the include path. So, you might have to move the files into your system's base include path folder, or define an additional include path via ini_set("include_path", ":extra path here").
    I know, but the file I'm trying to include is in the same directory as the script i'm trying to include them from. Hence the problem with the include_path shouldnt matter

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Strange coincidence here, as the code I'm working on right now is (or was until 2 minutes ago) generating exactly the same problems. I discovered the fix in this thread: include_path probs

    I this helps you!


Bookmarks

Posting Permissions

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