Answer the question
In order to leave comments, you need to log in
How to understand a large foreign code?
Good evening everyone!
They gave me a project, the project is very large, that is, even just to see how data is selected from the same search, you need to bypass a lot of different methods of different classes. At what stage is it better to put a breakpoint? Sometimes you put a breakpoint at the place where the array with the results is already returned. And sometimes it’s too early, and you go around all kinds of classes with this debugger, you don’t understand a thing, and again. Sometimes the debugger even throws it into the ClassLoader.
Is there a debugging strategy? In small projects (on frameworks), this is all easy, but in this situation, everything is not so rosy
Answer the question
In order to leave comments, you need to log in
First, just a debugger, from the entry point to the exit.
Understand how the application works by going through all the handlers.
You do it many times, each time stepping into a new level, until you determine how the controllers are called.
With this knowledge, next time you will know where to put the breakpoint (at the beginning of the controller).
I can help with this:
if(!function_exists('include_info')) {
function include_info($SCRIPT_FILENAME,$FILE) {
$f = substr($SCRIPT_FILENAME,strrpos($SCRIPT_FILENAME,'/') + 1);
$s = substr($FILE,strrpos($FILE,'\\') + 1);
if($f != $s) {
echo '<b>Файл ['.$s.'] подключен в файл ['.$f.']</b><br />';
} else echo '<b>Файл ['.$s.'] - прямой вызов</b><br />';
echo $f."<br>";
echo $s."<br>";
echo '$_SERVER["SCRIPT_FILENAME"]: '.$SCRIPT_FILENAME."<br>";
echo '__FILE__: '.$FILE."<br>";
}
}
....include in the head file (or via the PHP auto_prepend_file setting ). First, understand the data flows in order to understand where, what and when it goes.
This can be done without a debugger, just look at the code.
If there is no documentation, no common sense in the code, then I can only sympathize, because. without understanding "what is going on here" no debugger will help you.
It may sound strange, but in addition to debugging, use code formatting, placing comments with questions and a general description of your understanding with questions. Unload your head.
If there is an opportunity to communicate with the previous developer, then you should listen to the head of the transport department . At least in general terms to know the logic.
And one more piece of advice in context. If there is a lot of copy-paste and a mixture of a Georgian with a suitcase of php html js and css, then demand time to refactor the code before moving on to introducing new functionality. Otherwise, refuse.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question