[SOLVED] Debug doesn't work when breakpoint is inside if

hi
debug doesn't work when breakpoint is inside if statment or inside of block of code (such as loop , ...) that it needs true condition

Selection_079.jpg
does anybody has same problem or experince ?

10 comments

Hi there,

That is xdebug issue: it cannot stop on some lines -- http://youtrack.jetbrains.com/issue/WI-2191


Here is a simple code -- similar to yours:

<?php
$a
= 'abbra cadabra 22!'; echo $a, "\n"; $z = array('hello', 'world'); if ($a == 'abbra cadabra 22!')     foreach ($z as $v)         echo $v . "\n";


IDE will not stop (rather, xdebug will not issue breakpoint) on certain lines (like, on foreach line).

But it is very easy to fix: just add curly brackets {} where required:

if ($a == 'abbra cadabra 22!')
    foreach ($z as $v) {
        echo $v . "\n";
    }


Now it stops. MAGIC!

0

Not magic happend to me yet
i put everywhere bracks but it doesn't stop

Selection_081.jpg

0

Please extract your code (you can alter it as you wish) into separate file (project) to make reproducible code example so it can be used for testing by devs.

I've tred to reproduce the issue with my simple code and my solution worked for me (no idea if you have tried my code or not). Maybe your case is different -- I have no code and cannot verify it.

Also -- what xdebug version do you use? Try updating to the latest version (2.2.2 is the latest one; 2.2.1 works for sure).

0

Please attach your file to the forum post.

The site where you have uploaded it asks for registration and I have no plans to register on some site just to download some random file.

0

Thanks.

So ... from this example -- which foreach (I mean -- which breakpoint) does not work: first or second?

(Notice that I have added curly braces to both if/cycles).

if (!empty($exclude_pattern)) {
    foreach ($exclude_pattern as $pattern) {
        if (preg_match("/$pattern/i", $msg)) {
            return true;
        }
    }
}

if ($counter_permit && !empty($exclude_num_pattern)) {
    foreach ($exclude_num_pattern as $pattern) {
        if (preg_match("/$pattern/i", $msg)) {
            return true;
        }
    }
}
0

this code is extract the previous screenshot

i put break point to first block (that has bracks)

should i put bracks for all codes before it ?

0

As you can see from the screenshot below, it works for me:
screen01.png
The breakpoint on second foreach works (after adding curly braces, of course) -- I can step inside it (current execution line has blue background).

Breakpoint on first foreach will never be triggered using your example -- and it is NOT a bug (neither PhpStorm or xdebug)

0

yes you are right
solved
i put break points on wrong statment

0

Please sign in to leave a comment.