Array count shown in Debug panel

When stepping through code using the debugger, usually there will be one or more arrays in the code. Oftentimes it would be very helpful to know how many elements are in each array. In the case of PHP indexed arrays, one can simply expand any one of the arrays and scroll down to see the last (and highest) key value. But in the case of associative arrays, there is no way to know the number of elements without manually counting them, which can be very time-consuming for large arrays and essentially impossible for huge ones. It would be wonderful if, when the user hovers his mouse pointer over the name of an array in the Debug panel, a tooltip pops up showing the number of elements in the array.

That would be helpful. For now you should be able to use the REPL when in a breakpoint. Then you can use language specific tools to find out how many elements are in your array.

I hadn’t thought of that possibility as a workaround. But the docs suggest REPL is Python-specific?

I agree it would be a helpful feature.

It’s definitely not just Python but maybe PHP doesn’t have a REPL? ya looks like PHP has no REPL :(. Nvm.

It has.

https://secure.php.net/manual/en/features.commandline.interactive.php

Hmmm, not sure why it doesn’t work in the debugger then.

I guess it’s not working because it requires PHP to be complied with a special flag. Without it, running php -a will enable Interactive Mode, which works by reading anything from STDIN, waiting for ^D and then executing everything you wrote.

Well there you go?

You can use a watch expression to evaluate the length of the array in question without jumping through all of the REPL hoops.

I can see how one could use a watch expression to stop at a breakpoint when an array element is set to a particular value, but I don’t see how that can be used to output the number of elements in an array.

Sorry, a Watch Expression in the “Watch” tab of the debug pane. Not a breakpoint watch expression.

Thanks for the clarification. I’ve never before used that “Watch” tab. So to try it, in my code I put $array = [1, 2]; and in the “Watch” tab I put count( $array ), but the value output (in the “Value” column) is “can not get property”. Same result if I append a semicolon, like count( $array );. Any ideas on where I’m going astray?

Clipboard01

@mjross, This might not be supported in PHP. We don’t have a interpreter shell and I suspect that functionality is needed for this to work. I’ll file it to investigate though.

  • Carey

Okay. Thanks!