Different modules often require additional code added to the same php file(s), and as you have observed, after installing one module, a second module may also affect a file (or files) that was altered by the first module.
If (like 99% of us) you have only a smattering of PHP knowledge (or less), getting things to work is often a process of trial and error.
So the key to your "experimentation procedure" is making sure you backup any file(s) that require a manual edit so that if (after your edits) the website falls over, it's simply a case of loading up the ORIGINAL file(s) and starting over.
Often (but not always), the ORDER in which lines of code appear in a PHP file, is important, because there may be a chronology to the processing of the code. (The PHP must perform "A" before it is is allowed to perform "B", and then it goes on to process "C"...). This is typical of many CONDITIONAL bits of code... (IF...ELSE statements).
Then there are PHP files that just need to LIST things like functions and operations. When needed, the list is simply "scrolled through " until the calling command finds the code driving the function it was told to collect, which it then uses to perform whatever action was called for. An example of this are language DEFINE statements which are listed one by one under each other. (There will be a "visual" order to these to make them easier to find, but generally it does not matter if define statement "A" is above or below define statement "B").
At other times (typically in TEMPLATE files), the location of a piece of code influences the position (or behaviour) of an element in the displayed HTML in a browser, and a key indictor of this, is evidence of php being embedded into (or surrounded by) HTML tags.
So, try to establish whether the clip of code you need to add is important for any CHRONOLOGY in behaviour, or important for any POSITIONING on the final "page", or whether it just needs to be there to describe a FUNCTION that needs to happen.
Again, there's no real danger in making a mistake in a PHP file IF you have a backup of the original file that you can restore if things go pear-shaped.
Where modules require database changes (SQL Inserts), things can be a little different. Getting the php edits wrong in these cases can result in errors that involve calls to the database.



