The same code as the teacher, error:
Fatal error: Cannot declare function Demo2\test because the name is already in use in E:\wwwroot\phpbase\object\namespace\test2.php on line 5
test1 code:
<?php
namespace Demo1;
function test($a,$b)
{
return $a*$b;
}
?>
test2 code:
<?php
namespace Demo2;
require('test1.php');
use function Demo1\test;
function test($a,$b)
{
return $a $b%
王先生2019-10-18 18:12:30
The teacher's code is to solve this kind of duplication of names. His demonstration is not wrong, but if we use the same code, we will be wrong.
老老宋2019-10-18 18:03:47
test2 itself has a test method, and then the test1 you introduced also has a test method
If the same method exists in the same .php, you will get the error above
http://php.wyscdz .com
王先生2019-10-18 16:59:48
The above error is that the PHP version is 7.0.12
If you switch back to 5.6.27, the following error will be reported:
Fatal error: Call to undefined function Demo1\test()