TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-15-2008, 03:02 AM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default Namespaes?

I just got the newsletter... what exactly are namespaces?
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-15-2008, 03:30 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I'm sure others can give you a better description, but in a nutshell, namespaces are essentially a way in which to cipher of various code into namespaces. Think of a namespace as a category. Therefore anything in that category can have the same function name as another function in a different namespace (or category).

Basically, when you and others develop a PHP script now, you'll see you have to append some text that identifies your script to each class you create for that script, but with namespaces you can place all your classes in a namespace and all the classes within there can be named whatever you like, because they won't conflict with anything else.

Welcome back to TalkPHP by the way It's a pleasure to have you round again!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
Aaron (01-15-2008)
Old 01-15-2008, 04:13 AM   #3 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

I still don't get what namespaces are. Any real world examples?
__________________
Necessity is the mother of invention.

My blog
Haris is offline  
Reply With Quote
Old 01-15-2008, 07:44 AM   #4 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Default

PHP: Namespaces - Manual
sjaq is offline  
Reply With Quote
The Following User Says Thank You to sjaq For This Useful Post:
Aaron (01-15-2008)
Old 01-15-2008, 12:44 PM   #5 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Thanks for the welcome O.o.

I didn't think I was gone that long! (I was caught up in school work, and trying to find a good book on MySQL).

So a namespace is something used in OOP?
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-15-2008, 01:03 PM   #6 (permalink)
The Contributor
 
buggabill's Avatar
 
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
buggabill is on a distinguished road
Default

Correct me if I am wrong, but from my very limited understanding, it appears to give classes their own level of scope. PHP classes were totally global before. This meant that if you named your class something like getUserName, no one else could in a large project. Namespaces will allow duplicate class names to happen in instances where more than one library in a project might have similar functionality. Before, one would have to append some sort of unique prefix to the class name in order to insure its uniqueness. This could have resulted in very long class names.
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
buggabill is offline  
Reply With Quote
Old 01-18-2008, 12:37 AM   #7 (permalink)
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
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:01 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design