Last Updated: 23 Jan 2024
|
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.
// don't include trailing slashes in URL or path constants define('MY_URL', 'http://www.startupcto.com'); define('MY_PATH', '/var/www/html/documents');
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 pgsql vs. mysqli vs. PDO vs. Zend_DB page.
Discussion
Right on-this helped me sort thigns right out.