PHP:空白页,错误报告不起作用 [英] PHP: Blank page, error reporting not functioning

查看:39
本文介绍了PHP:空白页,错误报告不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个空白页,尽管我已告诉PHP报告所有错误,但仍然没有得到任何结果,这使我相信这一定是语法错误.我什么都找不到.

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?

推荐答案

我认为 require(database.php); 应该是 require('database.php'); .

尝试更改它,看看是否有帮助

Try changing that and see if it helps

此外,您还缺少分号

return $arrayDump

编辑

好的,我不太确定,但是请尝试从函数的参数中删除强制类型转换.

Okay, I'm not too sure, but try to remove the casting from the parameters of the functions.

所以...

public function __construct(Config $config, array $constants = null, boolean $caseInsensitive = false) 

将会

public function __construct($config, $constants = null, $caseInsensitive = false)  {

我在PHP中并没有做太多的OOC,只是再拍一张.

I don't do much OOC in PHP, but just taking another shot.

这篇关于PHP:空白页,错误报告不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆