Earlier, we learned how to use namespaces.
Let's learn how to use namespaces shortly. Use the use keyword.
use namespace\class as short name;
For example, if you shorten \hello\hello, the namespace you used earlier to hh,
use \hello\hello as hh;
Let's see if it works by example.
<?php
namespace hello;
class hello
{
function hello()
{
return 'first hello class.';
}
}
namespace hello2;
class hello
{
function hello()
{
return 'second hello class.';
}
}
use \hello\hello as hh;
use \hello2\hello as hh2;
$helloFirst = new hh;
echo $helloFirst->hello();
echo '<br>';
$helloSecond = new hh2;
echo $helloSecond->hello();
?>
Result
If you use this once, you can save a little bit later.
Thank you for visiting. If you have any inquiry or explanation of mistakes, please use the comments below.
ALL COMMENTS 0
Sort by