Question

I'm stepping through the source code of CodeIgniter with Xdebug in NetBeans and I'm looking for a way to see defined constants as they are defined. If it's not possible, are there any other ways to display all defined constants?

Was it helpful?

Solution

Take a look at the get_defined_constants function. It will return an array of all the defined constants in the code up to the point of the function call. You can then use print_r to print out the array.

OTHER TIPS

This kind of practice I use is quite decent as it shows only custom/user created constants.

print_r(var_export(get_defined_constants(true)['user'], true));

Wrap this within pre tags or just view source and you'll get very nice array of all the stuff You defined.

Note that this is not going to work with php 5.3.* where in 5.4.* it outputs fine.

In earlier versions of php, get_defined_constants() must be assigned to a variable first, before output. Something like this.

$gdc = get_defined_constants(true);
print_r( var_export($gdc['user'], true) );

You probably want to adapt:

$arr = get_defined_vars();

The best I could find is to press F7 (step into) while in debug mode to have your constant line executed.

define('SOME_CONSTANT','VALUE');

And then double click "SOME_CONSTANT", right click and chose add new watch (shortcut: shift + ctrl + F7), and the add new watch window will appear with the constant prepopulated, select enter and you should see your constant value in the Variables (if you have the blue diamond selected "Show watches inside variables view") & Watches window panel.

Also quite handy to know, you can hover over variables to see their value as opposed to looking in the Debugging > Variables window panel...just need to turn it on as it's off by default...apparently buggy...using the latest xdebug and it's been fine for me so far.

Tools > Options > PHP > General Tab > Debugging Section > Check Watches and Balloon evaluation

Hopefully this will still be useful 2 years later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top