Example of good PHP namespace usage?
am 19.03.2010 08:05:47 von Dante Lorenso
All,
I want to start using PHP namespaces for my projects. Currently, I name
my classes similar to how Zend Framework names theirs and I end up with
classes like:
LS_Util_String
I'm thinking that if I converted this to namespaces, the classes would
be named like:
LS\Util\String
I'd like to look at an example of an open source project that has
already adopted namespaces as "the way to do it" and would be a good
best practices case for how I should go about setting up my library
namespaces.
I have been playing with concepts of using a Java-like naming convention
for classes and have created my own namespace like:
com\larkspark\util\String
And here I was thinking that packages would be lowercase and classes
would be camelcase with initial caps.
I'm getting ready to build a new project and wanted to do it in the
future-forward style while removing legacy classes and refactoring
everything to use namespaces.
Any examples out there? Everything I find from searching Google is
novice intro to PHP namespaces blogs, but nothing concrete. Also since
namespaces are relatively new, I see a lot of misleading guides where
they are using "::" instead of "\" to separate class name parts. What
does this list recommend?
Dante
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Example of good PHP namespace usage?
am 19.03.2010 16:12:20 von Adam Richardson
--00504502d33b14fe3d048228c614
Content-Type: text/plain; charset=ISO-8859-1
On Fri, Mar 19, 2010 at 3:05 AM, D. Dante Lorenso wrote:
> All,
>
> I want to start using PHP namespaces for my projects. Currently, I name my
> classes similar to how Zend Framework names theirs and I end up with classes
> like:
>
> LS_Util_String
>
> I'm thinking that if I converted this to namespaces, the classes would be
> named like:
>
> LS\Util\String
>
> I'd like to look at an example of an open source project that has already
> adopted namespaces as "the way to do it" and would be a good best practices
> case for how I should go about setting up my library namespaces.
>
> I have been playing with concepts of using a Java-like naming convention
> for classes and have created my own namespace like:
>
> com\larkspark\util\String
>
> And here I was thinking that packages would be lowercase and classes would
> be camelcase with initial caps.
>
> I'm getting ready to build a new project and wanted to do it in the
> future-forward style while removing legacy classes and refactoring
> everything to use namespaces.
>
> Any examples out there? Everything I find from searching Google is novice
> intro to PHP namespaces blogs, but nothing concrete. Also since namespaces
> are relatively new, I see a lot of misleading guides where they are using
> "::" instead of "\" to separate class name parts. What does this list
> recommend?
>
> Dante
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I'm certainly not advocating my framework's conventions as "the way to do
it", but you can certainly look at my code just to see how I'm using
namespaces for my project. The framework takes a largely functional
approach, so some of the Object-naming conventions aren't present, but you
still might see some things you like (or hate.) It seems to work well with
Netbeans (I haven't tried other IDE's.)
http://code.google.com/p/nephtali/
Documentation and other stuff can be found at the website in my signature,
if it would help to sift through the functions.
Adam
--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com
--00504502d33b14fe3d048228c614--