嵌套的require_once具有绝对路径不起作用 [英] nested require_once with absolute path not working

查看:99
本文介绍了嵌套的require_once具有绝对路径不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个三重嵌套的 require_once

user@mybox:/tmp/foo $ cat bar.php 
<?php
ini_set('display_errors', 1);
require_once 'foo3.php';

user@mybox:/tmp/foo $ cat foo3.php 
<?php

require_once 'foo2.php';
echo "foo3" . PHP_EOL;

user@mybox:/tmp/foo $ cat foo2.php 
<?php

require_once 'foo.php';
echo "foo2" . PHP_EOL;

user@mybox:/tmp/foo $ cat foo.php 
<?php

require_once 'Mage.php';

echo "foo" . PHP_EOL;

user@mybox:/tmp/foo $ cat Mage.php 
<?php

die('require once works' . PHP_EOL);

这有效:调用 php bar.php 我得到输出一旦工作就需要

This works: When calling php bar.php I get the output require once works.

如果我现在更改 foo.php 使用绝对路径:

If I now change foo.php to use the absolute path:

user@mybox:/tmp/foo $ cat foo.php
<?php

require_once '/tmp/foo/Mage.php';

echo "foo" . PHP_EOL;

我得到以下输出:

user@mybox:/tmp/foo $ php bar.php 
foo
foo2
foo3

最后一个文件的包含不起作用。

And the include of the last file does not work.

非嵌套 require_once 也可以工作:

user@mybox:/tmp/foo $ php foo.php 
require once works

这仅在某些机器上发生(具有相同的PHP版本PHP 5.3。 3(cli)(内置:2014年8月6日05:09:45)

This only happens on some machines (with identical PHP version PHP 5.3.3 (cli) (built: Aug 6 2014 05:09:45)

update

php foo2.php 

也不起作用

推荐答案

我们发现仅使用绝对路径是可行的。混合似乎是问题所在。

We found out that using only absolute paths works. The mix seems to be the problem.

这篇关于嵌套的require_once具有绝对路径不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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