Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未生成预期结果的基本PHP代码_Php - Fatal编程技术网

未生成预期结果的基本PHP代码

未生成预期结果的基本PHP代码,php,Php,下面的bones.php和index.php(取自Juravich、CouchDB和php Web Development)应该会在我的浏览器中产生以下结果: 如果我进去,我就会看到Home这个词。 如果我输入,我会看到“注册”一词。 相反,我得到的是空白页。我已经检查了打字错误,因为这是直接从书中抄出来的。但是作为PHP的新手,我不知道这个错误是作者的,还是更可能是我的 以下是index.php的代码: <?php include 'lib/bones.php'; g

下面的bones.php和index.php(取自Juravich、CouchDB和php Web Development)应该会在我的浏览器中产生以下结果:
如果我进去,我就会看到Home这个词。
如果我输入,我会看到“注册”一词。
相反,我得到的是空白页。我已经检查了打字错误,因为这是直接从书中抄出来的。但是作为PHP的新手,我不知道这个错误是作者的,还是更可能是我的

以下是index.php的代码:

<?php 
    include 'lib/bones.php';

    get('/', function($app) {
        echo "Home";
    });

    get('/signup', function($app) {
        echo "Signup";
    });

是否有错误报告?通常空白页是错误的。请尝试用括号括起include语句,如
include('lib/bones')如何打开错误报告?我正在使用Firefox。下面是我对UnstableEagle的回应。UnstableEagle:那没用。我很确定它正在调用bones.php,就像我纠正某些拼写错误之前一样,我收到了解析错误通知。请尝试添加
error\u reporting(-1);/要启用所有错误ini\U集合(“显示错误”,1);ini设置(“显示启动错误”,1)。在生产中(在实时网站上),您不希望显示错误。还可以使用
@
标记用户。是否有错误报告?通常空白页是错误的。请尝试用括号括起include语句,如
include('lib/bones')如何打开错误报告?我正在使用Firefox。下面是我对UnstableEagle的回应。UnstableEagle:那没用。我很确定它正在调用bones.php,就像我纠正某些拼写错误之前一样,我收到了解析错误通知。请尝试添加
error\u reporting(-1);/要启用所有错误ini\U集合(“显示错误”,1);ini设置(“显示启动错误”,1)。在生产中(在实时网站上),您不希望显示错误。还可以使用
@
标记用户。
<?php 

ini_set('display_errors', 'On');
error_reporting(E_ERROR | E_PARSE);

function get($route, $callback) {
    Bones::register($route, $callback);
}


class Bones {
    private static $instance;
    public static $route_found = false;
    public $route = '';


    public function _contruct() {
        $this->route = $this->get_route();
    }

    public static function get_instance() {
        if (!isset(self::$instance)) {
            self::$instance = new Bones();          
        }

        return self::$instance;
    }



    public static function register($route, $callback) {
        $bones = static::get_instance();

        if ($route == $bones->route && !static::$route_found) {
            static::$route_found = true;
            echo $callback($bones);
        } else {
            return false;
        }
    }


    protected function get_route() {
        parse_str($_SERVER['QUERY_STRING'], $route);
        if ($route) {
            return '/' . $route ['request'];
        } else {
            return '/';
        }
    }

}