UPDATE -- working on getting WAMP with phpDeveloper/Xdebug going. I still want NetBeans -- I just want to compare, see if I get some insights.


I am using NetBeans 6.9 with LAMP and Xdebug to work on PHP code. The Variables display works well, but lately it works less well. For example below, $authorized should be visible in the variables pane below the code and should expose its value. But it doesn't show, nor its value, and mousing over the code doesn't help. (The $this object is showing and it does go on and on, but $authorized isn't in there, and it wouldn't make sense if it were.)

This behavior is consistent. Maybe it's a function of the complexity of the code? Or rampant object usage? it seems to have started when I took up CodeIgniter.

Of course the variables are hidden when I need them most ... or so it seems to the poor human. What am I missing?

NetBeans debugger http://themanthursday.com/wiki/Debugger_Display.png

There's a better example below. When I'm stepping through this code, Variables displays only Superglobals and $this, just as in the picture. I can't see any values, even mere strings.

(Nagging thought: I bet the $CI SuperObject has something to do with all this ...)

class Product_documents {
  function getProductImage_all($id)
//Return an array of all documents for this product
{
  $imgPath = $this->_getProductImage_folder($id);
  $arrayPossibleFilenames = $this->_getProductImage_possible_files($id);
  foreach ($arrayPossibleFilenames as $imgFile) {
    $imgPathFull = $imgPath.$imgFile;

    $file_exists = get_file_info($imgPathFull);
    if ($file_exists) 
    {
    $arrayFilesPresent[] = $imgPathFull;
    }
  }
  return $arrayFilesPresent;        
}
}
Answer

Right click on the variable pane. Select "Filters". You will find the secret.

  • 9
Reply Report
      • 2
    • Couldn't you just tell what this "secret" consists of instead? I'd like to know without having to install NetBeans on my iPad.
      • 1
    • This 'secret' lists types of variables that are shown in the debugger. Unitialized and null variables are not shown by default. Additionally, in php.ini under [xdebug], set xdebug.show_local_vars=1 if you want all the local variables - very important.
      • 1
    • Thanks Kamal. Ironically, I deleted NetBeans today, having moved back to phpDesigner Pro ... and having given up on CodeIgniter some time ago. I will continue to watch this post with interest, however. BTW, I concluded that CI's use of the singleton pattern was the key; I wonder if "the secret" you offered would validate that.

Came across this site that has a very nice link to an Xdebug page that walks one through the process of upgrading Xdebug by compiling a 'more latest' version:

http://icephoenix.us/php/xdebug-doesnt-show-local-variables-in-komodo-netbeans-or-eclipse-pdt/

Variables inside by objects/classes are showing up again! Yeah!

No watches, no 'this may make Xdebug freak out' messages - just good ol' variables that now fully expose the failure of my solution... (haha).

David

  • 6
Reply Report

I've seen stuff like this before in Netbeans. I expect it's just a bug involving Netbean's interaction with XDebug. One possible workaround that I've seen before is adding a "Watch" for the variable that you can't see. For your example, you could go to the "Watches" tab and type in $authorized. It should show up once it has been set.

  • 2
Reply Report
    • Thanks, good idea. Using a watch didn't occur to me, only because in VBA they seem to be especially ineffective. I have to 'think outside the box' -- or to say it more rightly, I have to think inside a different box.
      • 1
    • Yeah, unfortunately, this particular box might not always be the best environment to think in :P
    • Sorry to say, I been busy and have not tried this -- but I hope to try it tonight. As for the WAMP experiment, I still need to finish out with a working xDebug. (Sometimes I just I wish I could do my work in real-time. Ha ha.)
    • CONCLUSIONS: FIRST, Setting a watch works. Now in the screenshot above, $this and Superglobals are joined by a 3rd line, which is the watch. SECOND, I like Steven's 'just a bug' theory. THIRD, phpDesigner debugging seemed awkward (debugging for master page didn't stop at a breakpoint in a different page). So I couldn't get to a comparison test. I am sure with more effort, I could figure it out and make the comparison. IN CONCLUSION, NetBeans is workable (HOORAY) with this extra insight.
      • 2
    • Bad after-conclusion: Using a watch worked on NetBeans on the WinXP machine. On home Ubuntu, setting watches to enabled causes Xdebug to completely boink.

I think it comes down to the singleton pattern that is implemented in CodeIgniter as "Super Object". I never have restarted this project to test Kamal's idea. Shortly after he posted, I concluded the singleton was the reason (I did not try to guess whether Kamal has the solution or not). Thus my response to this post.

  • 0
Reply Report

(2015) In php.ini under [xdebug], set xdebug.show_local_vars=1 if you want all the local variables in debug mode.

  • 0
Reply Report
      • 2
    • It doesn't do what you think. From xdebug.org/docs/all_settings :: When this setting is set to something != 0 Xdebug's generated stack dumps in error situations will also show all variables in the top-most scope. Beware that this might generate a lot of information, and is therefore turned off by default.

Try initializing $authorized to bool false.

I've seen Netbeans not show me variables initialized with a return value from a function without a doctype, but it's hit or miss enough to not be make a pattern out of.

  • -1
Reply Report
    • I added this just above the breakpoint: $authorized = FALSE; No Change. Is that what you meant? Also, after posting I realized I can produce a more interesting example of unexposed variables ... I may work that up a bit later.
      • 2
    • -1 because the suggestion didn't work, so the bounty ought to go somewhere else probably. But thank you Fanis for the suggestion.
      • 1
    • No worries. Like I said, it's hit or miss for me. Something else I've noticed is it will occasionally fail to pick up variables in the global scope if the script being debugged has no functions.

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions