0

I thought, constructions like if(){}-else{} are so common, that I would never have problems with this. But...with next code my brain is blowing up. Need any advice. Subject is:

//print_r($_SESSION);
/*array(    
[filterSub] => Array
        (
            [app] => vedushchiye
            [workin] => Array
                (
                    [0] => vecherinka
                )
        )
)*/
$catCur = 'vedushchiye'; //for example
if (!empty($_SESSION['filterSub']) && isset($_SESSION['filterSub']['app']) && !empty($_SESSION['filterSub']['app']) && $_SESSION['filterSub']['app'] != $catCur && $catCur != 'performers'){
                $_SESSION['filterSub']['workin'] = array();
                echo ' stage 2 ok ';
            }

So, I expected that the condition will not run.

And it really did not run, but this part $_SESSION['filterSub']['workin'] = array(); ran and echo ' stage 2 ok '; wasn't.

How is it possible?

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
  • 2
    How are you determining whether something "did run" or "did not run"? – David Oct 21 '15 at 22:50
  • Are you intending on those comments being in there? – Shawn Mehan Oct 21 '15 at 22:51
  • Have you used error reporting to determine the break points of the code? IE `ini_set('display_errors',1);` `ini_set('display_startup_errors',1);` `error_reporting(-1);` – Zak Oct 21 '15 at 22:57
  • @David if this condition ran, i should see "stage 2 ok", and I don't see it. But workin in session became empty array – Alex Komlev Oct 21 '15 at 23:01
  • @Zak yes, used ini_set('display_errors',1); error_reporting(-1); . Nothing – Alex Komlev Oct 21 '15 at 23:02
  • 1
    You may have some other code that's setting the session variable. – Barmar Oct 21 '15 at 23:06
  • How exactly are you checking that "workin in session became empty array"? Can you post the results of `print_r($_SESSION)` immediately after your `if` statement completes? – Matt Gibson Oct 21 '15 at 23:08
  • @Barmar no, I checked everywhere. – Alex Komlev Oct 21 '15 at 23:10
  • (As a side note, you could simplify that conditional, bearing in mind that [a combined `isset()` and `!empty()` are redundant](http://stackoverflow.com/questions/4559925/why-check-both-isset-and-empty)). – Matt Gibson Oct 21 '15 at 23:11
  • 1
    Working as expected here: https://3v4l.org/mCW55 - your best chance is probably to set up a debugger like e.g. https://netbeans.org/kb/docs/php/debugging.html – VolkerK Oct 22 '15 at 01:14

0 Answers0