11 Bad coding practices should be avoided by PHP developer

PHP bad coding practices. As a quick or lazy PHP developer here are 11 Bad coding practices should be avoided by PHP developer. Read list to check, if you have any of them.

Most of PHP developer due to tight dead line or some other reasons. Spoil there coding practices and make habit of some bad coding practices which listed below.

Listed mistakes or PHP bad coding practices are minor but it make project code too much complex for future maintenance.

PHP bad coding practices
PHP bad coding practices

PHP bad coding practices by PHP developer

Check out list of PHP bad coding practices and try to avoid it if possible.

Not check variable set(define)

Not check alien variable set(define) or not and use variable direct in process.


//bad
if ($_GET['page'] == 1) {
    // stuff
}

//good
if (isset($_GET['page']) && $_GET['page'] == 1) {
    // stuff
}


Suggested Post: PHP IF ELSE ELSEIF conditional statements best practices


Inconsistent spacing

Well spaced code looks clean and easy to understand, some PHP developer not follow this spacing practice.


//bad 
if (expression) {
code line 1
code line 2
    code line 3
code line 4
    
    }

//good
if (expression) {
    code line 1
    code line 2
    code line 3
    code line 4
}

Never define function argument type – Type Hinting

It is good if function argument have defined type( Type Hinting ), so when developer use function and pass wrong type argument PHP stop it.


//bad 
function myFunction($myarr, $entryId) {
    //stuff
}

//good
function myFunction(array $myarr, integer $entryId) {
    //stuff
}

All code in one file

Not analyze code and write code in same file based on requirement.

At the end file becomes too large and hard to manage.

Improper or No comments

Some business logic are too much complex and always looks hard in update process.

As a Quick PHP developer and PHP bad coding practices developer write rough comment or avoid it, which create problem in future maintenance.

Not follow any coding pattern

There are too many great PHP framework, which have their own accepted PHP patterns.

But some master developer not follow useful pattern and find quick shortcut in development. It good practice to follow coding pattern.

Not follow variable name and file name rules

Not follow variable name and file name rules and set name which not fully describe variable or file meaning.

Always in hurry

Write code always in hurry and never think too long so produce code work for long time and multiple purpose.

Make main focus on complete module instead of create reusable code.

Duplicate code

Not analyze common process or not use tools to find duplicate code blocks and paste repeated duplicate code in every files.

It will hard time when change require in process which duplicate in many files.

Avoid testing

Some developer have too much confidence or laziness, they write code and not even test one time.

Mostly it check in production and you know better what happen when this type of code deployed in production.

Love fixes

Avoid proper problem solution due to more work or efforts and love small quick fixes.

Conclusion

Here is conclusion for 11 Bad coding practices should be avoided by PHP developer.

Hope you found Bad coding practices list useful and found something new to became better PHP programmer. If you found other bad practices points around your development world, you can point out in comment section.

Don’t forget to share List of “11 Bad coding practices should be avoided by PHP developer”.