Writing PHP Refactoring Code

As far as I know and gathered from other SO posts, there are no proper tools for refactoring PHP code, so when it comes to refactoring, this is probably a good old search and replacement for most of us, a lot of prayers that we don’t missed.

I would like to know if there are any coding recommendations on how to write code suitable for manual refactoring. Never create variable names from strings, this will be one thing that comes to mind, because such a construction is impossible to grep:

$object->{"field_".$fieldname}

I could imagine that there are several such cases and is not necessary. Maybe someone knows some good resources / articles on this. This should also not be specific to PHP.

+5
source share
5 answers

Unit tests always help me identify the places where I broke the code due to refactoring. Unit tests in dynamic languages ​​(PHP, Ruby, Python, etc.) Provide help when static typing in other languages ​​(Java, C #) usually allows you to reorganize more safely.

+5
source

Avoid magic as much as possible: variable variables, eval, masking errors with @ and storing code in the database will return to bite you.

+3
source

, - , - .

, - .

, , -, .., - .

.

+1

. , , , , , . ?

0

-, , . , , , , , ( , ..)

-, , IDE. Netbeans . , , ..

0

All Articles