PHP使用包含内部函数

我试图创建一个我可以调用函数,如下所示,
view( 'archive','post.PHP' );

而这个功能真正起作用的是什么.

include( 'view/archive/post.PHP' );

原因是如果将来我将目录扩展为view / archive / another_level / post.PHP我不想在我的代码中回到任何地方并更改所有包含路径.

目前这是我的功能,除了看起来include正在函数内部调用,而不是在调用函数时被调用

function view( $view,$file )
    {
        switch ( $view )
        {
            case 'archive'  : $view = 'archive/temp';   break;
            case 'single'   : $view = 'single';     break;
        }

        include( TEMPLATEPATH . "/view/{$view}/{$file}" );
    }

如何才能使此功能正确包含该文件

编辑:

没有显示错误.感谢@Ramesh的错误检查代码,ini_set(‘display_errors’,’On’)我能够看到包含文件中还有其他“未显示错误,这似乎导致文件无法显示起来……

该用例是 explicitly documented

If the include occurs inside a function within the calling file,then
all of the code contained in the called file will behave as though it
had been defined inside that function. So,it will follow the variable
scope of that function. An exception to this rule are magic constants
which are evaluated by the parser before the include occurs.

恕我直言,在常量中保持基本路径更简单(你似乎已经在某种程度上做了)或甚至进行全站点搜索和替换(在任何体面的编辑器中这是一个30秒的任务),而不是重写所有包含的文件使用全局变量.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...