0

I'm just using a single-dimension array, nothing special

$invalid_custom_transaction_ids = array();

Method 1:

foreach($result as $row) {
    if($row['TransactionID'] == $paypal_transaction_id) {
        error_log("[DIE]1");
        die();
    }
    error_log("[PUSHING]".$row['CustomTransID']);
    array_push($invalid_custom_transaction_ids, $row['CustomTransID']);
}

Method 2:

foreach($result as $row) {
    if($row['TransactionID'] == $paypal_transaction_id) {
        error_log("[DIE]1");
        die();
    }
    error_log("[PUSHING]".$row['CustomTransID']);
    $invalid_custom_transaction_ids[] = $row['CustomTransID'];
}

The following is printed to the debug log, showing that there are values that I've tried adding to the array()

[03-Nov-2014 08:48:25 America/Los_Angeles] [PUSHING]Ux837Yn3rK3

When I try to print the array to the debug_log using the following code

    error_log(var_dump($invalid_custom_transaction_ids));

it returns blank, I've also tried this

    error_log(array_values($invalid_custom_transaction_ids));

Output to the error_log file looks like this:

[03-Nov-2014 08:48:25 America/Los_Angeles]

Then the following error is printed

[03-Nov-2014 08:48:25 America/Los_Angeles] PHP Warning: Invalid argument supplied for foreach() in /path/to/script.php on line 195

The code that is on line 195 is as follow:

function uniqueTransactionCheck() {
    error_log("[UTC]1");
    error_log(var_dump($invalid_custom_transaction_ids));
    error_log("Is array: " . is_array($invalid_custom_transaction_ids));
    foreach($invalid_custom_transaction_ids as $invalid) {
        if($custom_transaction_id == $invalid) {
            $custom_transaction_id = generateTransactionID();
            uniqueTransactionCheck();
        }
    }
}

What's the deal? I don't understand this at all, I've been trying and trying to get this right, and shuffling through different documentaries and methods. I'm absolutely flabbergasted.


-snip-

2
  • Maybe the $invalid_custom_transactions_ids is empty, and therefor the foreach() will throw that error... Try to var_dump() it and die() to see if you have something in it for sure... Commented Nov 3, 2014 at 17:01
  • It would really be better to see your code as-is, rather than broken apart into pieces where we don't know the relation between one piece and another. Commented Nov 3, 2014 at 17:03

1 Answer 1

2

Your mistake is that var_dump does not return a string. It prints to standard output. When you write error_log(var_dump(...)) it is not writing the var_dump output to your error log.

It looks to me that the type of the variable is not an array as you expect. Can you print out the result of is_array($invalid_custom_transaction_ids)?

EDIT:

Ok so your issue is that in uniqueTransactionCheck() you are referencing a variable called $invalid_custom_transaction_ids.

However, that variable does not exist in the scope of uniqueTransactionCheck(). You probably want to pass the variable as an argument. If you run the following code in uniqueTransactionCheck() you will see false printed in your logs:

error_log(isset($invalid_custom_transaction_ids))

Sign up to request clarification or add additional context in comments.

6 Comments

Does error_log(array_values($invalid_custom_transaction_ids)); also not return anything? Either way, this doesn't explain why the foreach() is refusing to handle the array
@Christian.tucker Obviously it is not an array.
$invalid_custom_transaction_ids = array(); and array_push($invalid_custom_transaction_ids, $row['CustomTransID']);.. so it's obviously supposed to be one.
@Christian.tucker See my edit. $invalid_custom_transaction_ids is not an array in the function you are getting the error.
[03-Nov-2014 09:08:50 America/Los_Angeles] Is array: -- The results of is_array($invalid_custom_transaction_ids) return blank.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.