如果您有两个文件,file-a.php
和file-b.php
file-a.php
内容:
require 'file-b.php';
my_test( 'hi' );
和file-b.php
内容:
function my_test( $text ) {
echo $text;
}
然后"嗨"正如预期的那样回应。
但如果在file-b.php
中你在第一行添加一个回报,就像这样:
return;
function my_test( $text ) {
echo $text;
}
然后没有什么是回声,但也没有错误通知说" my_test"方法没有在任何地方声明。 为什么会这样?我期待一个未声明的功能错误。
编辑:澄清。如果我然后制作file-a.php内容:
require 'file-b.php';
my_test( 'hi' );
my_second_test_that_doesnt_exist( 'hi' );
然后我确实接到了对未定义功能的调用" my_second_test_that_doesnt_exist"'
答案 0 :(得分:0)
您正从文件中返回。所以一切都在线下"返回"没有被执行。但它会被PHP注意到,所以即使你不能调用它,PHP也知道它存在,所以它不会抛出错误。