0

I got an error in my code Trying to access array offset on value of type bool in the last line of my code:

        global $SESSION_FOLDER;
            $filename=$SESSION_FOLDER.'/'.$id;
            
            ob_start(); 
            $data=file($filename);
            ob_end_clean();
                
            $result=array();
list($type,$balance,$pm,$ref)=explode(':',$data[0]);
jeremysawesome
  • 7,033
  • 5
  • 33
  • 37
  • 1
    Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-warning-undefined-arr) – Markus Zeller May 29 '23 at 15:06
  • Look the file function return types: file(string $filename, int $flags = 0, ?resource $context = null): array|false – Med May 29 '23 at 15:31
  • Good morning. PHP's [`file` method](https://www.php.net/manual/en/function.file.php) will return `false` if there was a failure reading the file. In this case it's likely that `$data` contains `false` and you get the error you mentioned in your title. You'll need to fix the issue that is causing `file` to return false. Check that your file exists at the path you specify, and is readable by the process running php. – jeremysawesome May 29 '23 at 15:31
  • explode is used to seperate arrays.. are you sure $data[0] contains an array ? or you i think you are trying to use implode().. please clarify – HUNAIN AHMED 1002 May 29 '23 at 17:09

0 Answers0