0

Background
I am a .NET developer and usually work with C# in Visual Studio. I'm used to having a fully integrated development environment (IDE) where I can debug my programs, use breakpoints, and see how data is being passed through my applications. However, in my new role (I've recently switched jobs), I've had to learn PHP - I've only been working with PHP for about a month - and am using Visual Studio Code.

Context
I am working on a web application where one of the features is generating PDF documents. We are using TCPDF. This is an already existing program, over ten years old - I'm coming in and working on some enhancement tasks.

When a user gets data from a nightly report, they can generate notifications in mass for clients - notifications alerting them of their invoices (whether they have an invoice, or are past due, etc.) However, when the user pulls up a specific client's account and clicks to view the notification generated for them, it generates a new PDF.

For whatever reason, the original developers chose to not save the PDF, or the data used to generate the PDF. Instead, when the user requests to view an already generated PDF, it generates a brand-new PDF. The issue is that the logic provided in the PDF.php file is set to calculate data (i.e., total amount due) as of the day its generated.

I'm going through and adding logic to calculate the data using the date that the notification was processed. But herein lies my problem.

My Problem
As I said, this program is ages old. It was originally an Access program that was converted to PDF. It has years of tech debt and adheres to too little to no design principles - SOLID - and its architecture is terrible. I have spent days following through all the different SQL calls, looking at tables, jumping from file to file, etc. It's a complete mess.

However, the data I need is provided in the PDF.php file as an array. Instead of trying to piece together all the data being stored into this array, I want a way to just view the array.

I was shown a trick when working on an html file using var dump:

<pre>
   <?php var_dump(); ?>
</pre>

However, I'm not in an HTML file, I'm working in the PHP file that generates the PDF.

What I'm Looking For
Because of the nature of my development environment, I've not been able to use the debugging tools I'm familiar with (i.e., breakpoints), nor am I too familiar with VS Code - I'm still very much learning. I want a straightforward way where I can hover over an array as I make the request and have VS Code tell me what key => value data exists in the array.

Potentially Important Information
I'm not sure if this info makes a difference, but I want to provide as much background and context as possible.

  • We use SSH. I must connect my SSH using the terminal then launch VS Code as an admin.
  • I am using XAMPP and the XAMPP control panel to run my local host server for Apache and MySQL.
  • I am using PHP 7.

The control flow for the program is:

  1. On the client HTML, the button has a JS command: onclick="DisplayNotice()" where we pass in the notification name (we have three types of notifications), the mailing date, and the client ID.

  2. The JS file is tied to a form on the HTML. It sets the values for the form input fields (e.g., notification name, mailing date, client id) and then submits the form.

  3. The form opens a PHP file that houses a mysqli query object and try catch logic. In my case, we fall into the try, where we create a variable that creates a temporary record with the notification name, mailing date, and client ID.

  4. If the Record is valid, we create an instance of another PHP file and call a getNotifications() function where we pass in the notification name and client ID. We don't pass in the mailing date - but...

  5. In the PHP file where we the getNotifications() function lives, we build our SQL statement. in the SQL statement, we select the mailing date from the temporary record table.

  6. Then we run the SQL statement using our query object and save it as a variable. Then we call the setData() function and save the queried data in this function of our PDF.php file.

  7. And this is where the data now lives. And what's really got me confused is the way they've made the data accessible; they just created a foreach loop:

    foreach ($data as $row) {}

  8. How the foreach loop knows how to name the keys is beyond me. But the entire PDF logic (again, we're using TCPDF) exists within this foreach loop where we access the data using $row['key'].

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Can't you just see the contents in the debugger? – Dharman Nov 22 '21 at 17:17
  • 2
    VSCode comes with a PHP Debugger (XDEBUG) If you use that you can poke about all over the place at all the variables :) – RiggsFolly Nov 22 '21 at 17:18
  • 1
    _Small Point_ `var_dump();` is PHP and works in any php script. so use that on the array `var_dump($yourArray)` or for a simpler view of the data `print_r($yourArray)` – RiggsFolly Nov 22 '21 at 17:31
  • @RiggsFolly I think what OP meant is that they are not producing output visible on the screen, but rather a PDF file. Outputting anything would break the PDF file without showing the results. – Dharman Nov 22 '21 at 17:50
  • 2
    @Dharman You could be right, and as the OP wants a _Straightforward way where I can hover over an array as I make the request and have VS Code tell me what key => value_ then it looks like adding XDEBUG to the PHP config and then adding the VSCode extension – RiggsFolly Nov 22 '21 at 17:59

0 Answers0