如何使用initialize.php?

如何使用initialize.php?,php,Php,我想学习并使用initialize.php,因此我尝试构建简单的php文件,如index.php,只是想看看它是否调用hello.php,我在本地主机上使用windows xp获得了一些truble 详情如下: http://127.0.0.1/www/oop/shape2/index.php 文件index.php <?php defined('DS') ? null : define('DS', '/'); defined('SITE_ROOT') ? null :de

我想学习并使用initialize.php,因此我尝试构建简单的php文件,如index.php,只是想看看它是否调用hello.php,我在本地主机上使用windows xp获得了一些truble

详情如下:

http://127.0.0.1/www/oop/shape2/index.php 文件index.php

<?php
    defined('DS') ? null : define('DS', '/');
    defined('SITE_ROOT') ? null :defined('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);
    defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

    echo (LIB_PATH.DS.'hello.php');
    require_once(LIB_PATH.DS.'hello.php');
?>
<?php
 echo ('hi');
 ?>
http://127.0.0.1/www/oop/shape2/includes/hello.php 文件hello.php

<?php
    defined('DS') ? null : define('DS', '/');
    defined('SITE_ROOT') ? null :defined('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);
    defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

    echo (LIB_PATH.DS.'hello.php');
    require_once(LIB_PATH.DS.'hello.php');
?>
<?php
 echo ('hi');
 ?>

如果我运行它,我得到了
hi

这是我在windows上的本地文件夹: C:\Program Files\Zend\Apache2\htdocs\www\oop\shape2

我做什么来解决这个问题。
Thx

在第二行,您应该更改

已定义('SITE_ROOT')?null:已定义('SITE\u ROOT',$\u SERVER['DOCUMENT\u ROOT'])

已定义('SITE_ROOT')?null:define('SITE_ROOT',$_SERVER['DOCUMENT_ROOT'])


您调用的是
defined
函数,而不是
define
函数,这意味着您从未实际创建过SITE\u根常量。

什么是“initialize.php”?请注意,“echo hi;”是错误的,并将发出警告(“hi”表示您正在使用常量)。如果你想打印出“hi”,你需要使用:echo“hi”;(hi周围带双引号或单引号)。可以按相对于读取文件的位置上载一个目录或多个目录中的所有文件。您可能不知道
\uuuuu DIR\uuuu
\uuuuu FILE\uuuuuu
常量。不要滥用这样的三元运算。如果必须是一行,请使用
。例如:
定义('FOO')或define('FOO',1);
正确吗
输出是:C:/Program Files/Zend/Apache2/htdocs/includes/hello.php在那种状态下,代码是完全不可读的……但我想那看起来不错。你也试过了吗?是的,输出是:C:/Program Files/Zend/Apache2/htdocs/includes/hello.phpSo这意味着问题解决了吗?你呢现在可以包含您的文件了吗?