no0ob
no0ob

Reputation: 335

How to see the hierarchy of php files executed before a certain file

I have to use an old not well documented php CMS. I need to edit and add some codes which has weird hierarchy and i can't find the root file or the files in between which are needed to make change in stuff. Is it possible to find the file included this one or run before it? the main goal is to find full hierarchy but this should be enough to find them one by one.

Upvotes: 1

Views: 122

Answers (3)

Nanne
Nanne

Reputation: 64409

You don't want to spread debug code and vardumps all over the place: look into debugging and step trough your code. This is a bit of a learning curve but will help you.

For instance, use phpstorm and xdebug.

If you are set on using vscode, google says there are plugins for xdebug as well, so don't let that stop you: https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug

Every debugsession where you need to plaster var_dump and backtraces in your code is one that is costing you more time then it should -> sure, setting this up takes some time, but spent it. Even if it takes a day :D

Upvotes: 2

Sandeep Bangarh
Sandeep Bangarh

Reputation: 12

 $files = get_included_files();
     $section_data_array = array();
     $total_size = 0;
     $largest_size = 0;
     if (is_array($files)) {
         foreach ($files as $file) {
             $size = filesize($file);
             $section_data_array[] = array('data' => $file, 'size' => $size);
             $total_size = bcadd($total_size, $size);
             if ($size > $largest_size) {
                 $largest_size = $size;
             }
         }
         // endforeach;
         unset($file, $size);
     }

Upvotes: 0

Michal Bieda
Michal Bieda

Reputation: 939

You can try to use debug_backtrace and debug_print_backtrace functions.

Upvotes: 3

Related Questions