Connecting Multiple Classes with the Use Command in OOP in PHP
If you need to connect several classes,
each of them is connected with its own
use command:
<?php
namespace Users;
use \Core\Admin\Data1; // connect the class
use \Core\Admin\Data2; // connect the class
class Page extends Controller
{
public function __construct()
{
$data1 = new Data1; // call simply by name
$data2 = new Data2; // call simply by name
}
}
?>
Simplify the following code using
use:
<?php
namespace Project;
class Test
{
public function __construct()
{
$model = new \Core\Admin\Model;
$data = new \Core\Users\Storage\Data;
}
}
?>