Coding styles are upto the author of the code. IIRC there is no standard - and you can see that if you look at the existing PHP library.
| SitePoint Sponsor |
Coding styles are upto the author of the code. IIRC there is no standard - and you can see that if you look at the existing PHP library.
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona




arkinstall, i'm sure this has already been said somewhere or another, but i'm very impressed at your knowledge of PHP and OOP at only 16. if you make a career out of it, you're definitely going places.





I'm waiting for namespaces to use PHP's autoload. Otherwise, I'm committing myself to some very hideous conventions.
In the meantime (as of recently), I have been writing my classes in preparation of namespaces. I can grep for "require_once '...'" and "// PHPNS: namespace" and replace them with actual namespaces and use statements when PHP 5.3 comes about. Then, I can implement an autoload function cleanly with minimum work on my part later.
Slowly, PHP's becoming ever so less annoying. Hopefully, we'll be away from the current point where PHP is a b*****d child of Python's forgiving nature and Java's strictness.




GNU Coding standards? Is anything Zend GNU? PHP isn't GNU. Zend Framework isn't GNU. So why would the adopt GNU coding standards? O.o
Stolen from PHP.netQ. Why is PHP 4 not dual-licensed under the GNU General Public License (GPL) like PHP 3 was?
A. GPL enforces many restrictions on what can and cannot be done with the licensed code. The PHP developers decided to release PHP under a much more loose license (Apache-style), to help PHP become as popular as possible.
Lots of people create there own coding standards... Hell I even have my own coding standard which I adhere to from time to time Why? Because it makes me more efficient. If you ever work for an established software company, they will have there own coding standards that you will have to adopt with out hesitancy.
Creativity knows no other restraint than the
confines of a small mind. - Me
Geekly Humor
Oh baby! Check out the design patterns on that framework!


Autoloading classes is a huge time saver with larger projects, at least for me.
If you don't like the idea of automatic "rules", then define an array (probably want that moved to config) matching up classes with file paths for your autoload function.
Adrian Schneider - Web Developer





working on: Aperiplus, Rephactor, Phemto
useful links: xUnit test patterns, martinfowler.com, c2 wiki





It's just as easy to rename the file. Besides, how often do you write a class without having already settled on a name for it?




I was gonna stay out of this discussion...but I had to say that I don't think this is a similar scenario at all. not that i can think of a better analogy, but this isn't a good one.
one class per file, unless the class is a helper file, or you're intentionally compacting your files for performance reasons.





working on: Aperiplus, Rephactor, Phemto
useful links: xUnit test patterns, martinfowler.com, c2 wiki




refactoring is a part of developing, it shouldn't affect your conventions tho.


I'd have to agree with McGruff. I've changed names a lot in my most recent project. All of the classes sit in the same file and it would've been a serious drag if I had to keep up with changing filenames. However, I might consider breaking them out into individual files now that the design has solidified a bit and the usage scenarios are clearer. I actually won't though, because the code is used on almost every page, so I just include the file once in a common file. I'm using __autoload to load model classes though.




Mmm... I would say its more like writing an essay
Realistically, it doesn't matter what convention you use, so long as it gets the job done and you document it. If you don't have it documented, then you FAIL and should be LOL'ed to death for all eternity... I haven't slept yet... and its 9 am... sorry![]()
Creativity knows no other restraint than the
confines of a small mind. - Me
Geekly Humor
Oh baby! Check out the design patterns on that framework!





Interesting. When I wrote a lot of poetry, I would struggle for days with choosing a single word, feverishly thumbing through thesauri and Word Finder to find the most concise way to express a thought. I've seldom had that problem with class names though. The names usually just come to me as I'm writing the code, if indeed I don't already have a name chosen beforehand. That said, I did recently rename my JavaScript "Viewer" to "Presenter".![]()




I personally love the idea of the waterfall development paradigm. But I never have the patience to sit down and plan everything, naming all my classes, functions and so on. Its just so easy to figure it all out as I go. ._.
Creativity knows no other restraint than the
confines of a small mind. - Me
Geekly Humor
Oh baby! Check out the design patterns on that framework!




it's a lot easier when you're using existing design patterns that already have the naming spoon-fed to you. takes the thinking out of the whole deal.




Creativity knows no other restraint than the
confines of a small mind. - Me
Geekly Humor
Oh baby! Check out the design patterns on that framework!









you understand it correctly. i usually do something like $type$pattern, in PHP terms lol. so for instance:
SessionRegistry
UserController
DatabaseFactory
if it's a model that directly corresponds to a database table, the model's class name is just the singularized version of the database table name.
of course there's still some creativity needed...there isn't a pattern for everything, but it certainly helps reduce that.





Database table names should be singular anyway.




that convention is still up in the air for me. i've been using plural lately, but i don't have any convincing arguments either way.









so have we concluded that __autoload is not overrated?
Surely this:
Code sql:SELECT id FROM topics WHERE name IN('something', 'something else')
Makes more sense than:
Code sql:SELECT id FROM topic WHERE name IN('something', 'something else')
In the english sense.
I hope soso have we concluded that __autoload is not overrated?![]()
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
Bookmarks