Last Updated: 23 Jan 2024

   |   

Author: 114.119.150.49

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
backend-tech:php:best-practices [May 11, 2009 06:47 AM]
dordal
backend-tech:php:best-practices [Jan 19, 2024 04:26 PM]
110.249.202.47 removed
Line 1: Line 1:
 += PHP Best Practices =
  
 +== Leave the slash (/) off URLs, file paths, etc. ==
 +
 +At some point, you'll probably need to create constants with URLs or file paths. It's rather tempting to put a closing slash on the end, because it looks 'more complete', is fully qualified, etc. //Don't do it!// You'll end up finding yourself taking the slash off with ''rtrim()'' or similar all the time. Better to just leave the slash off, and add it if you need it. 
 +<code php>
 +// don't include trailing slashes in URL or path constants
 +define('MY_URL', 'http://www.startupcto.com');
 +define('MY_PATH', '/var/www/html/documents');
 +</code>
 +
 +== Use Native Database Extensions, not PDO, etc. ==
 +
 +I generally recommend you use native PHP database extensions, and not an abstraction layer like PDO. Read why on the [[mysqli-vs-pgsql-vs-pdo-vs-zend_db|pgsql vs. mysqli vs. PDO vs. Zend_DB]] page.