1

In the following function call the log files show me that even though before the return call the variable has a value the variable receiving the return value is empty

the if empty has just been included because I didn't believe what is happening.

What am I missing? Any clou?

    ...
    ...
    $workingProductArray=$this->placeNextItem($workingProductArray, ... );

    if (empty($workingProductArray)){
        write_log ("DYING array empty");
        die(); //<-- and indeed the system dies.
    }
}

private function placeNextItem(array $workingProductArray, ... )
{

    if ($this->areAllProductsIgnored($workingProductArray)){

        print_r($workingProductArray); // <-- SHOWS EXPECTED ARRAY AND VALUES
        return $workingProductArray; // returning this value
    }
0

2 Answers 2

1

Weird! Try to not print_r2 from placeNextItem function if still doesn't work try to name $workingProductArray to something else for placeNextItem.

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

1 Comment

thanks i was just digging into the code. and I just noticed I made a terrible thinking mistake... I call this frunction also from within (recursively), so apparently I thought the return statement would go to the method above but it goes back to it's recursive caller from within...
0

I was just digging into the code. and I just noticed I made a terrible thinking mistake... (which you can't see on the mentioned code... here the code to the function's end)

...
...
$workingProductArray=$this->placeNextItem($workingProductArray, ... );

if (empty($workingProductArray)){
    write_log ("DYING array empty");
    die(); //<-- and indeed the system dies.
}
}

private function placeNextItem(array $workingProductArray, ... ){

if ($this->areAllProductsIgnored($workingProductArray)){

    print_r($workingProductArray); // <-- SHOWS EXPECTED ARRAY AND VALUES
    return $workingProductArray; // returning this value
}
...
$this->placeNextItem(array $workingProductArray, ...);
}

So I call this function also from within (recursively), I thought the return statement would go to the method above but instead it goes (doh! off course!) back to it's recursive caller, which is the same method where I have to return the value too...

easy fix:

private function placeNextItem(array $workingProductArray, ... ){

if ($this->areAllProductsIgnored($workingProductArray)){

    print_r($workingProductArray); // <-- SHOWS EXPECTED ARRAY AND VALUES
    return $workingProductArray; // returning this value
}
...
return $this->placeNextItem(array $workingProductArray, ...);
}

Comments

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.