在PHP中包含文件的原则,而不是在C ++中 [英] The principle of include files in PHP, not as in C++

查看:74
本文介绍了在PHP中包含文件的原则,而不是在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法打开流:没有这样的文件或目录


我有这样的结构程序:


a.php is locate at。

b.php位于./lib

c.php位于./lib/sublib


a.php使用b.php中的函数,而b.php使用c.php中的函数


在a.php中,它说:include_once(./ lib / b.php )因为它在b.php中使用了一个函数



a.php不应该知道b.php正在使用c.php,所以它应该

不包括c.php。

在b.php中,它说:include_once(./ sublib / c.php)因为它使用了

函数在c.php中。

b.php不应该知道a.php使用自己,所以它不应该是b $ b包括lib作为include_once(../ lib / sublib / c.php),但它没有
工作。

问题是:...无法打开流:没有这样的文件或目录

的c.php。 .."


如果在b.php中使用include_once(../ lib / sublib / c.php),编译器就会很高兴。但它违反了包含文件的一般原则

只考虑自己在自己的位置,而不是考虑其他人b
使用它(也是,它不应该知道它)如在C ++中那样。

任何提示如何遵守上述原则?


谢谢。


D.

failed to open stream: No such file or directory

I have the programs like this structure:

a.php is locate at .
b.php is located at ./lib
c.php is located at ./lib/sublib

a.php uses a function at b.php while b.php using a function at c.php

In a.php, it says: include_once(./lib/b.php) as it uses one function
in b.php
a.php is not supposed to know that b.php is using c.php, so it should
not include c.php.
In b.php, it says: include_once(./sublib/c.php) since it uses a
function in c.php.
b.php is not supposed to know that a.php uses itself, so it should not
include lib as include_once(../lib/sublib/c.php), but it does not
work.
The problem is: "... failed to open stream: No such file or directory
of c.php. .."

If using include_once(../lib/sublib/c.php) in b.php, the compiler is
happy. But it violates the general principle of who include files
only considering itself at it own position, not considering others who
use it (also, it is not supposed to know it) as in C++.
Any hints how to obey the above principle?

Thanks.

D.

推荐答案

在我们的上一集中,< 11 ***************** ****@i13g2000prf.googlegroups。 com>,

可爱而有才华的 du ******* @ gmail.com 在comp.lang.php上播放:
In our last episode, <11*********************@i13g2000prf.googlegroups. com>,
the lovely and talented du*******@gmail.com broadcast on comp.lang.php:

如果我将程序移动到其他地方,使用绝对路径将会损坏,需要改变每个文件。
If I move the programs to other places, using absolute paths will
suffer, need to change every file.



通常我使用project.ini,我使用set_ini来修改项目的包含路径

,然后我就不必使用了包含的路径除了

到project.ini的路径(可能),但因为它是perl one-line更改

(如果有必要)我不知道看不出问题了。


PS:为什么./lib/b.php而不是lib / b.php?

-

Lars Eighner< http://larseighner.com/<tp://myspace.com/larseighner>

倒计时:462天。

当你被取消债券时你会怎么做?

Generally I use a project.ini where I use set_ini to modify the include path
for the project, then I never have to use paths in includes except for the
path to project.ini (possibly), but since it is a perl one-line to change
that (if necessary) I don''t see the problem.

PS: why ./lib/b.php instead of lib/b.php ?
--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 462 days to go.
What do you do when you''re debranded?


Lars Eighner写道:
Lars Eighner wrote:

我们的最后一篇剧集,< 11 ********************* @ i13g2000prf.googlegroups。 com>,

可爱而有才华的 du ******* @ gmail.com 在comp.lang.php上广播:
In our last episode, <11*********************@i13g2000prf.googlegroups. com>,
the lovely and talented du*******@gmail.com broadcast on comp.lang.php:

>如果我将程序移动到其他地方,使用绝对路径将会受到影响,需要更改每个文件。
>If I move the programs to other places, using absolute paths will
suffer, need to change every file.



一般我使用project.ini,我使用set_ini修改项目的包含路径

,然后我就不用了包含的路径除了

到project.ini的路径(可能),但因为它是perl one-line更改

(如果有必要)我不知道看不出问题了。


PS:为什么./lib/b.php而不是lib / b.php?


Generally I use a project.ini where I use set_ini to modify the include path
for the project, then I never have to use paths in includes except for the
path to project.ini (possibly), but since it is a perl one-line to change
that (if necessary) I don''t see the problem.

PS: why ./lib/b.php instead of lib/b.php ?



直到你遇到两个同名的文件......和两个不同的

套餐一样。


-

==================

删除x来自我的电子邮件地址

Jerry Stuckle

JDS计算机培训公司
js ******* @ attglobal.net

==================

Until you run into two files with the same name... As in two different
packages.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================




感谢您的帮助。你的所有建议都是在某处使用绝对的

路径。


实际上,这是我的场景,* SAME *文件名,不同位置:


a。一个PHP位于。叫./mylib.php

b。另一个php文件位于./lib/mylib.php

c。第三个php文件位于./lib/sublib/mylib.php

a调用b中的函数,而b调用c中的函数。


我是什么需要只是一个清晰的图片如何在a和b中包含文件,

即./mylib.php和./lib/mylib.php中没有任何问题

移动和将来的扩展。

我可以组织代码,但它看起来并不像

c / c ++那样透明,因为root文件必须考虑它'的孙子''

函数(位置),不应该用c / c ++来做。


再次感谢。

Du。


Thanks for your guys info. All your suggestions is to use absolute
path somewhere.

In fact, here is my scenario, *SAME* file name, different location:

a. one php is locate at . called ./mylib.php
b. another php file is located at ./lib/mylib.php
c. third php file is located at ./lib/sublib/mylib.php
a calls a function in b while b calls a function in c.

What I need is just a clear picture how to include files in a and b,
i.e. in ./mylib.php and in ./lib/mylib.php without any trouble when
moving and future extension.
I can organize the codes, but it does not seems as transparent as what
c/c++ does as one file at root have to consider it''s grandsons''
functions (location), not supposed to do that in c/c++.

Thanks again.

Du.


这篇关于在PHP中包含文件的原则,而不是在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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