require_once is being a pain in the butt
Posted: Sat Oct 04, 2008 12:36 am
I have had this issue a few times and I can never remember what causes it. I need to write it down next time I figure it out. Anyway... I've been working on several libraries I'm releasing on google code. In these libraries, I've tried to include_once every file that a particular file is dependant on. For instance, in php csv utils, I have a class called Csv_Reader_String which extends Csv_Reader. The file looks like this:
notice the require_once '../Reader.php' - shouldn't this look in the directory above where the file is for a file called Reader.php and include it if it hasn't been already?
With this code, I get Warning: require_once(../Reader.php) [function.require-once]: failed to open stream: No such file or directory in C:\wampalamp\www\svn\php-csv-utils\Csv\Reader\String.php on line 2
I don't get it. I look at that include path and I see "." (the current directory) as the first place it looks, and yet it says it can't find it. So I try "require_once 'Csv/Reader.php'" and I get:
Fatal error: Class 'Csv_Reader' not found in C:\wampalamp\www\svn\php-csv-utils\Csv\Reader\String.php on line 3
So I try "require 'Csv/Reader.php'" and I get:
Fatal error: Cannot redeclare class Csv_Reader in C:\wampalamp\www\svn\php-csv-utils\Csv\Reader.php on line 27
What in the world is going on??
notice the require_once '../Reader.php' - shouldn't this look in the directory above where the file is for a file called Reader.php and include it if it hasn't been already?
Code: Select all
<?php
require '../Reader.php';
class Csv_Reader_String extends Csv_Reader {
/**
*
*/
public function __construct($string, Csv_Dialect $dialect = null) {
if (is_null($dialect)) {
$dialect = $this->autoDetectFile($path);
}
$this->dialect = $dialect;
// if last character isn't a line-break add one
$lastchar = substr($string, strlen($string)-1, 1);
if ($lastchar !== $dialect->lineterminator) $string = $string . $dialect->lineterminator;
$this->handle = fopen("php://memory", 'w+'); // not sure if I should use php://memory or php://temp here
fwrite($this->handle, $string);
if ($this->handle === false) throw new Csv_Exception_FileNotFound('File does not exist or is not readable: "' . $path . '".');
$this->rewind();
}
}I don't get it. I look at that include path and I see "." (the current directory) as the first place it looks, and yet it says it can't find it. So I try "require_once 'Csv/Reader.php'" and I get:
Fatal error: Class 'Csv_Reader' not found in C:\wampalamp\www\svn\php-csv-utils\Csv\Reader\String.php on line 3
So I try "require 'Csv/Reader.php'" and I get:
Fatal error: Cannot redeclare class Csv_Reader in C:\wampalamp\www\svn\php-csv-utils\Csv\Reader.php on line 27
What in the world is going on??