php-best-practices

What I consider the best practices for web and software development.


Back to technical skills

Performance tips

Comparison

Don’t use loose comparison, always be as strict as possible.

// Bad:
if ($a == $b) {/* ... */}

// Good:
if ($a === $b) {/* ... */}

Using fully-qualified function calls

When calling functions in a namespaced context, additional actions are triggered in PHP which result in slower execution.

// solution 1:
namespace baz;
\foo();

// solution 2:
namespace baz;
use function foo;
foo();

References