Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] Namespaces

Joined
May 17, 2007
Messages
2,474
Reaction score
681
PHP how has namespaces & optional garbage collection? :p in it's new release 5.3.0 (said to be a big improvement from 5.2.X)

php.net said:
PHP 5.3.0 Released!

[30-Jun-2009] The PHP development team is proud to announce the immediate release of PHP . This release is a major improvement in the 5.X series, which includes a large number of new features and bug fixes.
Some of the key new features include: , , , optional for cyclic references, new extensions (like , and ), over 140 bug fixes and much more.
For users upgrading from PHP 5.2 there is a available here, detailing the changes between those releases and .
Further details about the release can be found in the , and the full list of changes are available in the .






 

Zen

Custom Title Activated
Loyal Member
Joined
Dec 2, 2006
Messages
1,621
Reaction score
152
wow. that will be great

time saving with
Code:
<?php
namespace MyProject;

const CONNECT_OK = 1;
class Connection { /* ... */ }
function connect() { /* ... */  }

?>
 
Newbie Spellweaver
Joined
Jan 1, 2009
Messages
46
Reaction score
1
I don't get what the namespaces do exactly. Can someone explain me better, without all the technical crap?
 
Joined
May 17, 2007
Messages
2,474
Reaction score
681
I don't get what the namespaces do exactly. Can someone explain me better, without all the technical crap?
They do what they do in any other programming langauge (that supports packaging / namespaces), basically organizes your scripts
some-what like the include function, but it calls directories instead of a single file (or as i would think)
 
Newbie Spellweaver
Joined
Jan 1, 2009
Messages
46
Reaction score
1
So like the good old days with batch:
Code:
:myshit (<-- namespace thingy 1)
REM Code here
REM morecode
REM even more

:myshit2 (<-- namespace thingy 2)
REM More code
If something = something GOTO myshit1 (<-- if condition, pointing to namespace thingy 1)

Or isn't that right? xD
 
Skilled Illusionist
Joined
Apr 22, 2009
Messages
301
Reaction score
19
Yes, but more sophisticated, more like C# using System.Net; etc...

Lets say you got 2 namespaces :

namespace1
namespace2

and in those 2 namespaces you got a functions print()

you could call namespace1 print() and namespace2 print() even if functions have the same name.
 
Newbie Spellweaver
Joined
Jan 1, 2009
Messages
46
Reaction score
1
Ah ok i get it a bit.

it's like having two seperate files in one ;P
 
Skilled Illusionist
Joined
Apr 22, 2009
Messages
301
Reaction score
19
You could see it as a two different boxes with tools inside them.
 
Custom Title Activated
Loyal Member
Joined
Aug 8, 2004
Messages
3,892
Reaction score
20
Truth be told, it's too little, too late.

Over the past decade or so programmers have worked on sophisticated frameworks that either do not require namespaces due to code factorisation by class (as does the one I helped develop and mostly use) or implement their own similar system (using the custom classloader PHP has).

In fact, because PHP did not use to have namespaces certain functions like a custom classloader and magic methods arose and proved to be far more effective than a seperation into namespaces / classes. Hell, they even allow you to create a framework that supports overloading in PHP if you can be bothered (which I would advice against, read my article - it's far too cumbersome).

Additionally, PHP 5.3 is not something just found on every webhost, thus for commercial purposes it is still not a feasable option. Maybe in the future when it is as common as 5.1 is now and a new framework is developed, but at the moment most one can do is play around with it.

Personally I'm much happier with the finally supported late static binding - now there's a feature we've been waiting on for years.
 
Back
Top