Php namespace problem, why F1 (); calls the function of the nearest space, they are all in the same space?

<?php
namespace first;
function f1(){
    echo "f1-1";
}
namespace second;
function f1(){
    echo "f1-2";
}
f1();

/ / Why did you output F1-2? are they all in the same space? The principle of proximity?

Mar.08,2021

your way of writing, F1 (); is obviously under the namespace second, it must be the second one, ah, there is no principle of proximity. You will know in the back
echo _ _ NAMESPACE__;.


single file multiple namespaces are best to use {} to divide the space scope

Menu