Solved

Could you check my logic on this, please?

Posted on 2016-07-27
3
38 Views
Last Modified: 2016-07-27
The dealbreaker, at this point, is the presence of an array. At least, that's what I've been able to deduce thus far.

Here's the first part of the process:

protected function processStatementSql ($sql) {

        $statements = StatementImage::runQuery($sql);
        $ret = array();

        //Second and Third DB Calls
        //TXN TABLE STUFF
        // NOTE - I don't know there is a reason to process these as separate queries
        // and I think they can be reasonably combined with the query held in getSQL()
        // and processed through to get the same dataset more quickly.
        if ($statements) {
            foreach($statements as $st) {
                $accountid = $st['AccountID'];

                if (!$st['StatementRollUp'] || $st['templateid'] == '9') {
                    $st['newtxns'] = StatementImage::getNewTransactions($st, $st['showphysician'] == '1');
                } else {
                    $st['newtxns'] = array();
                }

Open in new window


Look at line 15. $statements is a SELECT statement that's just been fired. We're going to parse it out as an array and when we get to $st['StatementRollUp'] we pause and ask a question...

if (!$st['StatementRollUp'] || $st['templateid'] == '9') {

Which, in plain language is asking, if the StatementRollUp value is not defined OR the template id is 9, then proceed with the getNewTransactions method. At which point, you've defining an index within an array ($st['newtxns'])  as the values represented by the getNewTransactions method.

Otherwise...

You've got the $st['newtxns'] array, but there's nothing in it.

The very next line of the code is this:

foreach($st['newtxns'] as $txn){
                    $st['lastclaimdate'] = $txn['firstdos'] < $st['lastclaimdate'] || $st['lastclaimdate'] === null ? $txn['firstdos'] : $st['lastclaimdate'];
                }

Open in new window


So, now that $st['newtxns'] is $txn.

I know. It's a mess. But be that as it may, I've been hired to fix what's there and not write new code. There's six years worth of original programming and the layers of nonsense are eternal.

So, here comes that $txn array and it's being looked at in the context of another IF statement:

  if (isset($encounter['txns'])) {

From here, the PDF that's being generated is formatted according to the result of this IF statement. My thought is that if your $encounter['txns'] array is devoid of content, then the result of the above IF clause is FALSE.

Agreed?
0
Comment
Question by:brucegust
3 Comments
 
LVL 51

Assisted Solution

by:Julian Hansen
Julian Hansen earned 150 total points
ID: 41731577
Think of it like this isset will return true if $encounter['txns'] exists i.e. if $encounter is an array AND index 'txns' is defined.

If $encounter is not an array or does not have an index 'txns' set, then isset will return false
0
 

Author Comment

by:brucegust
ID: 41731647
So...

It doesn't have anything to do with content. If both the array and the index have been defined, then this:

 if (isset($encounter['txns'])) {

...is TRUE. Both the array and the index have been defined and what's IN the array is not what's being looked at as much as it's THAT it's an array.

Yes?
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 350 total points
ID: 41731696
It doesn't have anything to do with content...

Not quite.  Variables may have been defined, then subsequently set to NULL or unset().  PHP isset() determines if a variable is set and is not NULL.  It returns TRUE if both cases are true for all of its arguments.

There really isn't any such thing as "devoid of content" unless you make an assignment of NULL to a variable.  And to fully understand what is happening to the PHP symbol table, you need to know the scope of the variables.

In the case of the $encounter array, it can be defined like this, but one of its member positions remains undefined:
<?php // demo/temp_brucegust.php
/**
 * https://www.experts-exchange.com/questions/28959883/Could-you-check-my-logic-on-this-please.html
 *
 * http://php.net/manual/en/function.var-dump.php
 * http://php.net/manual/en/function.error-reporting.php
 */

// WITH FULL ERROR REPORTING -- ALWAYS RECOMMENDED
error_reporting(E_ALL);

$encounter = [];
var_dump($encounter);
if (isset($encounter)) echo "encounter is defined";
if (isset($encounter['txns'])) echo "encounter.txns is defined";

Open in new window

Outputs:
array(0) { } encounter is defined

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now