Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

求分析include,require,include_once...这些引入文件的语句 #1

Open
kk8686 opened this issue Aug 16, 2016 · 5 comments
Open

Comments

@kk8686
Copy link

kk8686 commented Aug 16, 2016

发现网上有不少互相采集内容一样的相同文章,如这篇 :http://www.jb51.net/article/22467.htm
跟着做却发现require和include有的区别并不是那样,或者他说的并不是那么细致,求分析求真相谢谢

@boobusy
Copy link

boobusy commented Aug 16, 2016

不要使用once,尽量include。鸟哥有篇文章说的这个,具体BLOG

@kk8686
Copy link
Author

kk8686 commented Aug 16, 2016

我也尽量不用once的,但现在不是讨论用不用讨论的问题,是讨论两个函数之间的区别问题,我发现很多网上的文章存在误解或说明不详细,造成对读者的误导,所以希望能分析一下源码有个铁证,以防更多人被误导

@boobusy
Copy link

boobusy commented Aug 16, 2016

if (type==ZEND_REQUIRE) { zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename TSRMLS_CC); zend_bailout(); } else { zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename TSRMLS_CC); }

require与include的差别:错误信息的显示级别zend_bailout();
include输出错误信息时的级别为:E_WARNING
require输出错误信息时的级别为:E_WARNING + E_ERROR

对于once类型的, php每次引入会查全局表一次确认文件是否被引入过;
他们全是调用 zend_do_include_or_eval

@kk8686
Copy link
Author

kk8686 commented Aug 18, 2016

http://www.kkh86.com/it/php-base/guide-base2-include.html

这是我调试后得出的结论文章,虽不知底层是不是这样,调出来的效果就是这样了,你有空的话麻烦帮忙鉴定一下哈

说报错级别问题确实是个区别,但目前只能试出文件不存在时的错误,如果被引入的文件代码里有错误就一模一样了(可能处理的范围本身就不一样,两者可能无法一概而论,所以估计官方说的错误级别是指处理参数时的错误级别,而不是参数正确,文件存在,引入文件后的错误级别吧)

@hoohack
Copy link
Owner

hoohack commented Aug 18, 2016

@kk8686 多谢建议,这两天抽时间研究一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants