Php namespace inherits "use" from another class

Asked

Viewed 80 times

-1

It would be possible to "inherit" imports, use of a class? Example

Car.php

<?php

namespace app\model;

use app\Utils;
use app\Banco;

class Carro{}

main.php

<?php

namespace app\model;

use app\Carro;

class Main{
    $banco= new Banco();
}

Is there any way that this could be possible? Since class Car already have a use to "Bank".

  • Not, use no matter the class. If you need to use it again, there are no plausible reasons not to use the use again.

1 answer

0

No, namespaces are only for referencing and locating the object within its code structure having no reason to have inheritance or any business rule for it.

If you need to use the same methods and functions as another parent class then you enter the concept of inheritance, in this case you can also use TRAITS in the case of php to insert actions internally in the class.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.