Monday, June 02, 2008

NameSpace on PHP 5.3

Yippeeeeeeeeeeeeeeeeeeeeee...

I'm so enormously glad knowing that they going to add complete support of NAMESPACE in php engine !!!

I'm very an organized code kind a guy, and all this time, one of my difficulties on writing application with PHP is because it doesnt support namespace, which in turn giving me a hard time just for thinking their names

what's namespace for ?
my simple view its one way for a programmer to have structured built into application component logically, without have to enforced the code structure phisically (eg. prefixing class name).

for example conventional way to implement code structure in PHP is by using directories and prefix,
I would have such structure

/www
index.php
/protected
/controls
/engine
/manager =>manager related code
mgr_mod.php
mgr_priv.php
/user => user related code
usr_mod.php
usr_priv.php

whats up with the structure above ?
u see, to avoid name conflict I have no other way beside prefixing the class name, and this is annoying me because sometime I really want the same name for those classes(eg. mgr_mod.php and usr_mod.php should just be mod.php), because actually they doing the same thing but on different domain, --apart from Generality/specialties design concept because some time I'd like to "break the rules" :p --

why so, they are in different directories right ?
yes, that doesnt mean their logically in different places(this where namespace concept come up), because the whole application is a single namespace(well, actually there are no namespace at all) so even I've put those classes on different directories, their name musn't be the same, or PHP will throw an exception that said you have declared xx class more than once...

with namespace i could simplify my class naming (this is what i thought)

/www
index.php
/protected
/controls
/engine
/manager
mod.php
priv.php
/user
mod.php
priv.php

in mod.php for manager i would have
namespace Manager;
class mod {
...
}

and in mod.php for user I would have
namespace User;
class mod {
...
}

in modern Object Oriented Language, we have package for java, and namespace for .net (is it just me, or .net is "inspiring" php alot ??)
ofcourse, this isnt the only improvement that comes with 5.3 engine, but this is what thrill me the most..

well, actually I dont have time to test it, just got this info from http://ilia.ws, and theres a big probability that I've miss :p,
another reason is PHP 5.3 isnt in stable release yet, still you can get it from http://snaps.php.net/


cant wait till it stable..

2 comments:

deniar said...

Wah artikelnya bagus, nice2... boleh nih diposting juga di http://belajarpemrograman.net

Kebetulan yang ngisi para anak2 IT Telkom. Ceritanya mau nyaingin ilmukomputer nih....

Btw kalo mau ntar aku buatin acc juga di sana sebagai penulis jadi bisa ikutan nulis juga di sana. Gimana zef?

Zeft said...

sep, boleh tuh den.., klo mo nulis2 yang rada guna ntar gw pos jg deh ke situ, masalah acc email aja yaks :)

slack dot dna at gmail dot com