Welcome Guest, Not a member yet? Register   Sign In
Require, require_once, include and include_once not working correctly within hooks.
#1

[eluser]iancant[/eluser]
I seem to be having an issue including or requiring a file from within a hook file.
Code:
if(file_exists('C:/wamp/www/park_factor_network/system/application/shared/config/language.php'))
        {
            echo "yes";
            if(is_readable('C:/wamp/www/park_factor_network/system/application/shared/config/language.php'))
            {
                echo "is readable";
            }
            else
            {
                echo "is not readable";
            }

            require_once('C:/wamp/www/park_factor_network/system/application/shared/config/language.php') or die("Cannot Include Language Config");

            require_once('C:/wamp/www/park_factor_network/system/application/shared/config/some_file_that_is_not_there.php') or die("Cannot Include Language Config");

            require_once('system/application/shared/config/language.php') or die("Cannot Include Language Config");

            $fp = fopen('C:/wamp/www/park_factor_network/system/application/shared/config/language.php','r');
            fpassthru($fp);

            die();

        }
        else
        {
            echo "no";
        }

With this I get the following:
Code:
yes // result of file_exists()
is readable // result of is_readable()
A PHP Error was encountered

Severity: Warning

Message: require_once(1) [function.require-once]: failed to open stream: No such file or directory

Filename: hooks/select_language.php

Line Number: 25


Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.;C:\php5\pear') in C:\wamp\www\park_factor_network\system\application\shared\hooks\select_language.php on line 25

/* ########### // result of require_once() where file does exist ########### */

A PHP Error was encountered

Severity: Warning

Message: require_once(1) [function.require-once]: failed to open stream: No such file or directory

Filename: hooks/select_language.php

Line Number: 27


Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.;C:\php5\pear') in C:\wamp\www\park_factor_network\system\application\shared\hooks\select_language.php on line 27

/* ########### // result of require_once() where file does not exist ########### */

A PHP Error was encountered

Severity: Warning

Message: require_once(1) [function.require-once]: failed to open stream: No such file or directory

Filename: hooks/select_language.php

Line Number: 25


Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.;C:\php5\pear') in C:\wamp\www\park_factor_network\system\application\shared\hooks\select_language.php on line 25

/* ########### // result of require_once() with relative path ########### */

array('name' => 'English', 'folder' => 'english'), 'de'=> array('name' => 'German', 'folder' => 'german') ); /* |-------------------------------------------------------------------------- | Default Language |-------------------------------------------------------------------------- | | If no language is specified, which one to use? Must be in the array above | | en | */ $config['default_language'] = 'en'; /* End of file config.php */ /* Location: ./system/application/config/config.php */

/* ########### // result of fpassthru ########### */
(note I have rerun and commented out each require_once to show all parts of the code).

Operating System: Windows Vista
Web Server Package: WAMP - Apache 2.2.11 - PHP 5.3.1
Code Igniter: Version 1.7.2

If I create a require outside of code igniter's environment and try to include a file it:
a) works if the file exists
b) Warning: require_once(File_Does_Not_Exist.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\park_factor_network\shiter.php on line 3

Fatal error: require_once() [function.require]: Failed opening required 'File_Does_Not_Exist.php' (include_path='.;C:\php5\pear') in C:\wamp\www\park_factor_network\shiter.php on line 3
#2

[eluser]WanWizard[/eluser]
Safe mode enabled by any chance?
#3

[eluser]iancant[/eluser]
No safe mode enabled. I can include and require elsewhere, and CI's own includes and requires work fine, it seems to be only within hooks, the problem occurs.
#4

[eluser]WanWizard[/eluser]
Hmmm... Pretty sure that is not related. Hooks don't alter the way PHP works.

What worries me is this:
Code:
Message: require_once(1) [function.require-once]
Where does this (1) come from? Normally you see the filename being included here.
#5

[eluser]iancant[/eluser]
Exactly, I would say its a php error but it only occurs within hooks files.

It seems maybe that in this case php is having an issue resolving the files location? Has anyone had any issues with this before?
#6

[eluser]iancant[/eluser]
Hi,

Problem is solved, some very clever over on Stack Overflow came up with the answer, which in hindsight makes perfect sense.

I have <a href="http://stackoverflow.com/questions/3175178/require-once-and-include-once-not-resolving-files-correctly"> linked here</a> as the answers are very interesting read for any new php developer.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB