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%
You are very studious, big brother!
I do not know
The final result is 9
test2.php file
test1.php file
test1.php and test2.php are placed in different Demo1 and Demo2 folders
use function Demo1\test; Just remove this line
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.
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
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()