Array count shown in Debug panel


#1

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.


#2

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.


#3

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.


#4

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


#5

It has.

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


#6

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


#7

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.


#8

Well there you go?


#9

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


#10

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.


#11

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


#12

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


#13

@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

#14

Okay. Thanks!