ネームスペースの利点はこれだと思っている。
複数人で開発とかしているときに関数名やクラスなどが
かぶってしまう可能性ある、そういうのを
解決してくれるのがネームスペースということです。
<?php
namespace test\demo;
class test{
function demo():string
{
return "demo1\n";
}
}
namespace test\demo2;
class test{
function demo():string
{
return "demo2\n";
}
}
<?php
include_once "./index-6.php";
$demo = new test\demo\test();
print $demo->demo();
$demo = new test\demo2\test();
print $demo->demo();