We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
DPC2020: Top 10 PHP coding traps - Damien Seguy
PHP developers, beware of common coding traps and improve your code quality with expert insights and best practices from Damien Seguy.
-
Be aware of the different types of comparisons, such as loose and strict equality, and avoid using loose equality (
==) when possible. - Use parentheses to clarify the order of operations when using complex expressions.
-
Avoid using the array operator (
[]) with a function call, as it can lead to unexpected behavior. -
Use
trim()andstrip_tags()to cleanse input data before processing it. -
Be mindful of the difference between
isset()andarray_key_exists(), as they behave differently. -
Avoid using
echoto concatenate strings, as it can lead to unexpected behavior. -
Use
.to concatenate strings, and avoid using+to concatenate strings, as it can lead to unexpected behavior. -
Be aware of the memory implications of using
array_concat()andimplode(). - Consider using constants instead of static variables.
-
Be aware of the limitations of
define()and consider usingconstinstead. -
Avoid using
strpos()without specifying the second argument, as it can lead to unexpected behavior. -
Be mindful of the difference between
Officersand()when using function calls. -
Avoid using
eval()andcreate_function()when possible, as they can lead to security vulnerabilities. - Consider using a code analyzer, such as PHPStan, to detect errors and improve code quality.
-
Be aware of the different memory allocation strategies in PHP, and consider using
clearstatcache()to clear the cache. -
Avoid using
include()with a bare path, as it can lead to security vulnerabilities. -
Consider using
namespaceto organize code and avoid naming conflicts. - Be aware of the differences between PHP versions, and consider upgrading to a newer version if possible.
- Consider using a JavaScript runtime, such as Node.js, to run PHP code.
-
Avoid using
passthru()with an undefined variable, as it can lead to unexpected behavior.