Thread: Namespaes?
View Single Post
Old 01-18-2008, 12:37 AM   #7 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

namespaces can be used to help you organize your classes. More importantly, namespaces help programmers aviod name clashes and stupidly long class names (if we were to prefix class names to stop clashing) like this:

Zend_Search_Lucene_Analysis_Analyzer_Common_Text_C aseInsensitive

from what i have been reading, php's namespaces will look like this:
PHP Code:

namespace Sketch::DB;

class 
mysql
{
    
//class gubbings
    
public function connect()
    {
        echo 
'hellllllloooooooooo';
    }
}


//to use:

use Sketch::DB::mysql();

//or to make an alias (in this case DBConn):

use Sketch::DB::mysql() as DBConn;

//or just
 
use Sketch::DB
//(its the same as doing use Sketch::DB as DB, but in simple form)



//so you can invoke in he following ways for each of the methods listed above:

$pDb = new Sketch::DB::mysql();
//or
$pDb = new DBConn(); 
//or
$pDb = new DB::mysql(); 
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote