Namespace works within the PHP language as a kind of wrapper classes, interfaces, methods and attributes. Using it, you can avoid naming conflicts between the elements, thereby making it work as a kind of tweezers. You can compare the use of the Namespace as the directories in operating systems. For example, the same file name can exist in different directories, but never in the same directory. This assumption is shared using the Namespace.

namespace php

To use the Namespace within .php files, then please select the syntax of the name you want to use:

<?php

namespace Project1{

class Test{}

}

 

namespace Project2{

class Test{}

}

?>

In the above practical example, you can clearly understand the functioning of the namespace. Classes with the same name are created within different namespaces and no conflict is presented.

Including the creation of spaces using namespace, you can then use this important resource within the application program, indicating its path and by setting a kind of label so that access is facilitated, as shown in the following example:

                use Project1Test as Test1;

$var = new Test1;

 

Using the instruction “use” indicates that the path of Namespace to be used. Then, the statement “the” indicates the label which is to be used as a reference to the object to be instantiated. The variable “$ var” then gets the instance of the class from the label indicated for the namespace.

The usage of namespace is seen as an important enabler in the development process. With it, you can work with numerous references within the project, thus ensuring that there is a better use of the developed source code. In addition, peculiarities between classes that need to use the same name, on behalf of the developed architecture, can be implemented at no cost of production or further development.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.