php-mistakes
php-mistakes copied to clipboard
Biggest PHP developers mistakes with Notes
###Biggest PHP developers mistakes
####- http://php.com/ no explanation ####- Turn OFF all error reporting
error_reporting(0);
thats why errors or warnings appears randomly later! ####- Use @ intentionally to silence errors or exceptions
$result = @$my_lib->process($data);
a secure library will validate the external data and return false or an Exception if something fail so we can handle that properly
try {
$result = $my_lib->process($data);
} catch (Exception $e) {
//handler the error
}
Read more about Error Control Operators
####- Not use isset() or array_key_exists
if ($_POST['email']) {
$email = $_POST['email'];
}
sure an E_NOTICE-level error message will be issued if email key is not found ####- Wrong Comparison Operators
if ($a = value) { /* really what you want?*/ }
//Equal
if (1 == true) { /*true*/ }
//Identical
if( 1 === true) { /*false*/ }
In fact you should always use Identical operator ===
for comparing and save you the pain later.
-- More info in the link
####- Security: SQL injection or XSS attacks and others
you must use statments and properly encode all external data
####- Not read php-fig (Basic Coding Standard & Coding Style Guide ) nowadays we work for others people too, we share code and contribute with others developers, so this is a must guide ####- Learn PHP Frameworks like Symfony before learn PHP If you don't dominate OOP, ORM, interfaces, abstract classes, annotations and other basics in PHP you can not expect to really understand what are you winning with this Framework ###Contribute #####Miss some others common mistake ? Make Edit and make a Pull Request