Best Practices Book, Document, Web Site?
Best Practices Book, Document, Web Site?
am 01.03.2010 21:48:14 von Mike.Hansen
Is there a PHP Best Practices Book, Document, or web site that has =
information similar to Perl Best Practices but for PHP?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Best Practices Book, Document, Web Site?
am 02.03.2010 00:08:31 von Shawn McKenzie
Hansen, Mike wrote:
> Is there a PHP Best Practices Book, Document, or web site that has information similar to Perl Best Practices but for PHP?
>
I'm not familiar with the Perl one, so I don't know specifically what
you mean, but there are many "coding standards". Probably the Zend one
would be the closest:
http://framework.zend.com/manual/1.10/en/coding-standard.ove rview.html
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Best Practices Book, Document, Web Site?
am 02.03.2010 04:54:49 von pan
""Hansen, Mike"" wrote in message
news:7941B2693F32294AAF16C26B679A258D0EFDC318@csomb01.corp.a tmel.com...
Is there a PHP Best Practices Book, Document, or web site that has
information similar to Perl Best Practices but for PHP?
Yeah, it's hard to find this stuff.
A google search on {+"Best Practices" +"PHP"} returned only
4,340,000 hits.
Maybe, some day, someone will think to write something up.
Good luck.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Best Practices Book, Document, Web Site?
am 02.03.2010 06:24:15 von Rene Veerman
http://oreilly.com/php/index.html perhaps?
I dont know any free online best practice docs (other than the php.net
function comments) that sum it all up nicely.
But best practices are like coding standards; there are at least a few
that are (near-)equals.
Personally, the basis of my current coding style is as such:
- hungarianCasingConventionWithAbbreviationsWTFlikeSo
- almost always short names for variables in simple code < 40 lines
- almost always longer and descriptive names for more complicated code.
- usually short comments: explanations for noobs (to problem area)
- the rest of the "commenting" is done by the code using descriptive
var & function names
(last 3 points makes for "self-documented code")
- consolidate all logic in the script, so use specific sets
(_POST/_GET) rather than generic sets (_REQUEST)
- document it in script if behaviour is dependent on outside sources
(like php.ini)
- use of "config.php" in project rootdir to set DEFINE()s and any
global variables.
- use of adodb.sf.net for database abstraction.
- use a standarized directory structure for all php projects;
/project/.htaccess - RewriteRule -> php scripts
/project/php - all php scripts
/project/js - all javascript, including .js.php
/project/lib/component-x.y.z/ - all 3rd party libraries, regardless
of language, x.y.z=versionnum
/project/sql - sql init / maintenance scripts
(possibly) /project/theme/themeName/many.css(.php)
(or:) /project/css/some.css(.php)
(possibly:) /project/admin/
- use of an error handler that knows when to mail errors to developer,
when to print errs in browser and when not to, etc.
a "proper error handler". mine is still evolving.
- use of a standard debug output lib, called by a function that checks
config.php for a DEBUG_MODE define. prevents production machines from
showing debug info.
plug: my free http://mediabeez.ws/htmlMicroscope/ is kinda nice.
- push all input into DB through functions that prevent SQL insertion
(at least a filter through mysql_real_escape) and HTML/js/flash/etc
insertions (harder).
- an authentication scheme that can be called with simple functions,
but which also does checks on whether or not the IP that started the
session is the same as the IP making a request on a certain session.
- calling of the authentication scheme by nearly all scripts
- in any lenghty operation, design for continuation of the operation
when a given item fails.
example from OS file copiers: it stops when it needs to ask a
question. i rather design to "keep going", log all items that require
user interaction, and let the user deal with them when he/she has
time.
there's probably more that would make it into my best practices list,
but i'm gonna leave it at this for now..
On Mon, Mar 1, 2010 at 9:48 PM, Hansen, Mike wrote:
> Is there a PHP Best Practices Book, Document, or web site that has information similar to Perl Best Practices but for PHP?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Best Practices Book, Document, Web Site?
am 02.03.2010 15:44:47 von Paul M Foster
On Mon, Mar 01, 2010 at 01:48:14PM -0700, Hansen, Mike wrote:
> Is there a PHP Best Practices Book, Document, or web site that has information similar to Perl Best Practices but for PHP?
FWIW, we tried to create a thread to gather these "best practices"
ideas, and mostly what we got was arguments from people who took
exception one way or another.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Re: Best Practices Book, Document, Web Site?
am 02.03.2010 15:52:07 von Bob McConnell
From: pan
> ""Hansen, Mike"" wrote in message=20
>>
news:7941B2693F32294AAF16C26B679A258D0EFDC318@csomb01.corp.a tmel.com...
>> Is there a PHP Best Practices Book, Document, or web site that has=20
>> information similar to Perl Best Practices but for PHP?
>=20
> Yeah, it's hard to find this stuff.
>=20
> A google search on {+"Best Practices" +"PHP"} returned only
> 4,340,000 hits.
>=20
> Maybe, some day, someone will think to write something up.
The problem with this method is that scanning these results reveals
conflicting and contradictory recommendations that are all over the
place. Some are so old they may not even be valid PHP any more. Reading
even a small subset of these pages is an exercise in frustration. But
that makes sense as there doesn't appear to be any consistency nor
consensus within the community, or even within some of the larger
projects.
Speaking of consensus, based on a recent discussion on the Perl
Beginners mailing list, the Perl Best Practices book is now considered
to be deprecated among the active Perl community. Many of its
recommendations are obsolete and no longer used. It is long past due for
a major rewrite.
Bob McConnell
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Re: Best Practices Book, Document, Web Site?
am 02.03.2010 18:51:18 von Mike.Hansen
=20
> -----Original Message-----
> From: Bob McConnell [mailto:rvm@cbord.com]=20
> Sent: Tuesday, March 02, 2010 7:52 AM
> To: pan; php-general@lists.php.net
> Subject: RE: [PHP] Re: Best Practices Book, Document, Web Site?
>=20
> From: pan
> > ""Hansen, Mike"" wrote in message=20
> >>
> news:7941B2693F32294AAF16C26B679A258D0EFDC318@csomb01.corp.a tm
> el.com...
> >> Is there a PHP Best Practices Book, Document, or web site that has=20
> >> information similar to Perl Best Practices but for PHP?
> >=20
> > Yeah, it's hard to find this stuff.
> >=20
> > A google search on {+"Best Practices" +"PHP"} returned only
> > 4,340,000 hits.
> >=20
> > Maybe, some day, someone will think to write something up.
>=20
> The problem with this method is that scanning these results reveals
> conflicting and contradictory recommendations that are all over the
> place. Some are so old they may not even be valid PHP any=20
> more. Reading
> even a small subset of these pages is an exercise in frustration. But
> that makes sense as there doesn't appear to be any consistency nor
> consensus within the community, or even within some of the larger
> projects.
>=20
> Speaking of consensus, based on a recent discussion on the Perl
> Beginners mailing list, the Perl Best Practices book is now considered
> to be deprecated among the active Perl community. Many of its
> recommendations are obsolete and no longer used. It is long=20
> past due for
> a major rewrite.
>=20
> Bob McConnell
Yep. Perl Best Practices is due for a rewrite/update. I came across this =
page that attempts to update it:
http://www.perlfoundation.org/perl5/index.cgi?pbp_module_rec ommendation_c=
ommentary
For PHP, I'll stick with the PEAR recommendations and do the best I can =
with whatever is missing.
Thanks.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Best Practices Book, Document, Web Site?
am 02.03.2010 19:07:30 von Shawn McKenzie
Paul M Foster wrote:
> On Mon, Mar 01, 2010 at 01:48:14PM -0700, Hansen, Mike wrote:
>
>> Is there a PHP Best Practices Book, Document, or web site that has information similar to Perl Best Practices but for PHP?
>
> FWIW, we tried to create a thread to gather these "best practices"
> ideas, and mostly what we got was arguments from people who took
> exception one way or another.
>
> Paul
>
That is not correct. I take exception with your comments.
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Best Practices Book, Document, Web Site?
am 05.03.2010 22:21:00 von Ravi Menon
Other than coding standards, the other good read is:
(it seems to cover most topics I have ran into while maintaining a
high traffic site implemented in php 5):
http://phplens.com/lens/php-book/optimizing-debugging-php.ph p
It is 'best practices' from another angle - use of opcode cache (apc
etc..), output buffering and so on.
Coding standards vary a lot, so I would recommend sticking to one
style once a consensus is reached among the team and preferably
enforce it in automated fashion (e.g.
http://pear.php.net/package/PHP_CodeSniffer/ as a svn pre-commit
hook).
The other easily over-looked part I have seen in many php projects is
the code layout and directory structure, including dependency
management (library code vs business logic etc..), and more
importantly only exposing the main 'entry point' scripts (index.php or
controller.php in a MVC model) in a apache doc root. Many times I have
seen poorly laid out code that ends up getting deployed with the
entire code bases exposed in a apache doc root. If care is not taken
(e.g. naming some files .inc and no special apache rules to interpret
them as a php handler), it is a security nightmare with critical files
getting exposed.
I have my own layout suggestion which has worked well for us, and once
mastered, it makes everyone in the team very productive. Maybe this
can be a separate topic in its own right.
Ravi
On Tue, Mar 2, 2010 at 9:51 AM, Hansen, Mike wrote:
>
>
>> -----Original Message-----
>> From: Bob McConnell [mailto:rvm@cbord.com]
>> Sent: Tuesday, March 02, 2010 7:52 AM
>> To: pan; php-general@lists.php.net
>> Subject: RE: [PHP] Re: Best Practices Book, Document, Web Site?
>>
>> From: pan
>> > ""Hansen, Mike"" wrote in message
>> >>
>> news:7941B2693F32294AAF16C26B679A258D0EFDC318@csomb01.corp.a tm
>> el.com...
>> >> Is there a PHP Best Practices Book, Document, or web site that has
>> >> information similar to Perl Best Practices but for PHP?
>> >
>> > Yeah, it's hard to find this stuff.
>> >
>> > A google search on {+"Best Practices" +"PHP"} returned only
>> > 4,340,000 hits.
>> >
>> > Maybe, some day, someone will think to write something up.
>>
>> The problem with this method is that scanning these results reveals
>> conflicting and contradictory recommendations that are all over the
>> place. Some are so old they may not even be valid PHP any
>> more. Reading
>> even a small subset of these pages is an exercise in frustration. But
>> that makes sense as there doesn't appear to be any consistency nor
>> consensus within the community, or even within some of the larger
>> projects.
>>
>> Speaking of consensus, based on a recent discussion on the Perl
>> Beginners mailing list, the Perl Best Practices book is now considered
>> to be deprecated among the active Perl community. Many of its
>> recommendations are obsolete and no longer used. It is long
>> past due for
>> a major rewrite.
>>
>> Bob McConnell
>
> Yep. Perl Best Practices is due for a rewrite/update. I came across this page that attempts to update it:
> http://www.perlfoundation.org/perl5/index.cgi?pbp_module_rec ommendation_commentary
>
> For PHP, I'll stick with the PEAR recommendations and do the best I can with whatever is missing.
>
> Thanks.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php