Reputation: 13476
I am running into a blank page, and although I have told PHP to report all errors I still get nothing which leads me to believe it must be a syntax error. I can't find what it is though.
Here is the script I am working on:
test.php
<?php
ini_set('display_errors', '1');
require('database.php');
print("hello");
$config = new Config("lessons.db","data/");
$db = new Database($config, array('first', 'second', 'third', 'fourth'), true);
print_r($db->dumpToArray());
?>
database.php
<?php
class Config {
private
$_db
$_file,
$_directory,
$_delimiter,
$_columns;
public function __construct(string $file, string $directory = null, string $delimiter = "|") {
$_db = $directory.$file;
$_directory = $directory;
$_delimiter = $delimiter;
}
public function db() {
return $_db;
}
public function delimiter() {
return $_delimiter;
}
}
class Database {
private
$_config,
$_columns,
$_rows,
$_pointer;
public function __construct(Config $config, array $constants = null, boolean $caseInsensitive = false) {
$_config = $config;
is_readable ($_config->db())
or exit ("The database cannot be read");
if(!is_null($constants))
$this->defineColumns($constants, $caseInsensitive);
return;
}
private function connect(string $method) {
if (!($_pointer = @fopen($_config->db(), $method)) or printf("Unable to connect to database");
}
private function disconnect() {
fclose($_pointer);
}
private function defineColumns($constants, $caseInsensitive) {
for (var $i=0;$i<count($constants);$i++)
define($constants[i], $i, $caseInsensitive);
}
public function dumpToArray() {
$arrayDump = explode($_config->delimiter(), file($_config->db(), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
return $arrayDump;
}
public function getRowByValue($column, $value) {
$this->connect('r');
$rowNumber = 0;
while (!feof($_Pointer)) {
$row = explode($_config->delimiter(), fgets($dbPointer, 1024));
if ($row[$column] == $value) {
$this->disconnect();
return $row;
}
$rowNumber++;
}
$this->disconnect();
return false;
}
}
?>
Anyone can see what could be causing it?
Upvotes: 0
Views: 2030
Reputation: 31813
Tip
If you have a syntax error and are in a situation where the only way you can change the error_reporting/display_errors settings is in the script itself, you can still make it work.
The trick is to make another script that has no syntax errors, and in that script set your config options, and then include the suspected bad script.
<?php
error_reporting(-1); // show all
ini_set('display_errors', 1);
require 'file_with_parse_error.php';
Still, you should generally be able to change these settings in php.ini or webserver config files. And there's should be an error log available to look at in any case.
Then just request the url for that new script in your web browser.
Upvotes: 1
Reputation: 461
I think require(database.php);
should be require('database.php');
.
Try changing that and see if it helps
Also, you're missing a semicolon on
return $arrayDump
EDIT
Okay, I'm not too sure, but try to remove the casting from the parameters of the functions.
So...
public function __construct(Config $config, array $constants = null, boolean $caseInsensitive = false)
Would be
public function __construct($config, $constants = null, $caseInsensitive = false) {
I don't do much OOC in PHP, but just taking another shot.
Upvotes: 1
Reputation: 19284
Since you're unable to look at error logs, try throwing a bunch of print statements in your code and see what line is killing your script. If it's killing in your database.php script, throw some prints in and there.
<?php
ini_set('display_errors', '1');
require('database.php');
print "Test1";
print("hello");
print "Test2";
$config = new Config("lessons.db","data/");
print "Test3";
$db = new Database($config, array('first', 'second', 'third', 'fourth'), true);
print "Test4";
print_r($db->dumpToArray());
?>
Upvotes: 0
Reputation: 26583
there are other error reporting levels in php.ini - you might want to look into them.
Upvotes: 0
Reputation: 157839
Anyone can see what could be causing it?
Thats most wrong and inefficient way of looking for errors.
you can stare in your code for ages and even ask other people to do it, yet without any success.
Why not to just read the exact error message?
You were on the right track, but gave up.
As Flukey said in the comments, you have to check error log, which by default is the ame as web-server error log.
Watching the actual errors is the only proper way to correct your code.
Upvotes: 1
Reputation: 32145
At first glance... This won't fly
$db = new Database($config, ["first","second","third","fourth"], true);
Your Database class expects an array
$db = new Database($config, array('first', 'second', 'third', 'fourth'), true);
Upvotes: 1