We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I have a set of snippets that use a common PHP class in a file that begins with:

    <?php
    include "config.inc.php";
    if (!class_exists("Database")) { include "db.class.inc.php"; }
    ...
    


    I moved the code from a PHP 4 to a PHP 5 deployment, and now, although this file gets included fine from the snippet itself, the includes inside the class file are looking elsewhere for the files? Why is this and what’s the best way to handle this so it works in both situations...???
      • 32963
      • 1,732 Posts
      I think it’s best to use absolute paths. I’ve seen this error with php5 and some open_base_dir php setting.
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
      • Quote from: xwisdom at Jun 13, 2005, 07:33 PM

        I think it’s best to use absolute paths. I’ve seen this error with php5 and some open_base_dir php setting.

        That’s really not an option for me in my development cycle, as I need portable packages that can be easily deployed locally or on various remote servers (LAMP of course). And, I actually solved it by prefixing the file with dirname(__FILE__) like such...

        include(dirname(__FILE__).'/somefile.inc.php');
          • 32963
          • 1,732 Posts
          I was more thinking of $base_path

          e.g. include $base_path."assets/snippet/mysnippet/myfile.php";
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
          • Quote from: xwisdom at Jun 13, 2005, 07:58 PM

            I was more thinking of $base_path

            e.g. include $base_path."assets/snippet/mysnippet/myfile.php";


            That could be an option, however, it would be nice to have getBasePath(), getBaseURL(), and getSiteURL() functions in the API for use in snippets and snippet includes, without having to declare it as a global everytime.
              • 32963
              • 1,732 Posts
              Quote from: OpenGeek at Jun 13, 2005, 08:05 PM

              That could be an option, however, it would be nice to have getBasePath(), getBaseURL(), and getSiteURL() functions in the API for use in snippets and snippet includes, without having to declare it as a global everytime.

              Very good suggestion Jason. I think those will come in handy
                xWisdom
                www.xwisdomhtml.com
                The fear of the Lord is the beginning of wisdom:
                MODx Co-Founder - Create and do more with less.