Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6959205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:14:27+00:00 2026-05-27T15:14:27+00:00

I am writing a php cli script, and my includes and requires are generating

  • 0

I am writing a php cli script, and my includes and requires are generating errors.

“PHP Warning: include_once(SCRIPT FOLDER): failed to open stream:
Inappropriate ioctl for device in SCIPT PATH on line XX”

Im setting the working directory to the location of the script using

chdir(dirname(__FILE__));

and wrote a wrapper function to include files as such (just code fragments):

$this->_path = rtrim(realpath('./'), '/').'/';     
public function require_file($file)
{ 
  if (include_once $this->_path.$file === FALSE)
    $this->fatal_error('Missing config file (config.php)');
}

What am I doing wrong, or missing?


Answer: (can’t answer my own question less than 100 rep)

The proper thing to do when comparing return values from include is

if ((include 'file') === FALSE)

doing it in the wrong fashion will evaluate to include '', causing my error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:14:28+00:00Added an answer on May 27, 2026 at 3:14 pm

    Well, include_once is a special language construct, not a function. As such you shouldn’t try to use a return value from it (like === FALSE). The PHP manual entry on the topic says that “The include() construct will emit a warning if it cannot find a file” so, checking that === FALSE doesn’t help your situation.

    My recommendation would be to use a custom error handler that throws exceptions when PHP errors are raised. Then you could wrap your include_once in a try/catch block to handle the exception caused by the invalid include however you like.

    So, for example …

    function require_file($file)
    { 
      set_error_handler(function($errno, $errstr) { throw new Exception($errstr); });
      try {
        include_once $file;
        restore_error_handler();
        echo 'woot!';
      } catch (Exception $e) {
        echo 'doh!';
      }
    }
    $file = 'invalid_filename.php';
    require_file($file); // outputs: doh!
    

    Note: I use a closure in this example. If you’re working with < PHP5.3 you’d need to use an actual function for the error handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a php script to compare the similarity of 2 strings. This works
I'm writing a PHP script and the script outputs a simple text file log
I'm writing a PHP script that does a lot of repetitive work, and when
I have a really puzzling problem: I am writing a PHP CLI application running
I'm writing a PHP script that I want to disable from web access (I
What is faster: writing PHP code using functions or writing it as pure script?
Im writing a php script that is used to update a database but it
I am currently writing a php script that validates a username and password. I
I'm writing a php script that will fetch data from a given URL and
The standard way of writing PHP extensions is to use autoconf/automake alongside a script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.