HOW TO implement using of namespaces?

Talk and info about common issues

Moderator: alexandrleonenko

administrator
Site Admin
Site Admin
Posts: 6001
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO implement using of namespaces?

Postby administrator » Sep 11th, '13, 15:42

Namespaces feature in PHP was added to the language from PHP 5.3.

Below the example of using namespaces in DataGrid script.

1. Add the first line in classes/helper.class.php after <?php to be:

Code: Select all

namespace DataGridProject;


2. Add the first line in classes/sqlparser.class.php after <?php to be:

Code: Select all

namespace DataGridProject;


3. Open datagrid.class.php file find every occurrence of Helper:: or SqlParser:: and replace with following
Helper:: -- > DataGridProject\Helper::
SqlParser:: -- > DataGridProject\SqlParser::

so you will get something like:

Code: Select all

DataGridProject\SqlParser::ParseString($this->sqlView)->getCountQuery();


Now you may be sure that Helper and SqlParser will nor overlap any other class with the same name.


to get more information about using of namespaces, read this:
http://php.net/manual/en/language.namespaces.faq.php

Return to “ApPHP DataGrid {HOW TO}”