Getting Detailed Information About Variables


 var_dump(false); 


The values of variables can be sent to the client using print() or echo(); however, this is sometimes problematic. Take Booleans, for instance. echo(true) prints 1, but echo(false) prints nothing. A much better way is to use var_dump(), a function that also prints the type of the variable. Therefore, this code returns the string bool(false).

This also works for objects and arrays, making var_dump() a must-have option for developers who like to debug without a debugger.

NOTE

A function related to var_dump() is var_export(). It works similarly; however, there are two differences:

  • The return value of var_export() is PHP code; for instance, var_export(false) returns false.

  • If the second parameter provided to var_export() is the Boolean true, the function does not print anything, but returns a string.





PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net