How to instantiate a PHP class

0

Generally to instantiate and use a class in my project, I use:

include ('arquivo_que_contem_a_classe.php'); 
$obj = new obj(); 
$obj->nomedafunction();

But today I needed an already ready class downloaded from github via composer, which created some directories and an autoload.php file.

In the use example of this class, you could use it as follows:

$obj = new \dir1\dir1\dir3([
  'var1'        =>  'var1', 
  'var2'    =>  'var2', 
  'var3'   =>  'var3', 
  'var4'    =>  'var4']); 

$executa = $obj->nomedafunction(); 

I did not understand the method of instantiating this class. I do not know how to search this in Google, so here asking for a force to explain to me how it works.

Note: The above codes are just examples.

    
asked by anonymous 07.08.2018 / 00:01

1 answer

2

This is a feature called namespace

link

It serves to separate your classes in a logical way, but they need to be "included" in the same way ... but the autoload of the composer already does this for you, being necessary only to refer them in this way

    
07.08.2018 / 15:18