Documentation

Dumping Variables - Zend_Debug

Dumping Variables

The static method Zend_Debug::dump() prints or returns information about an expression. This simple technique of debugging is common because it is easy to use in an ad hoc fashion and requires no initialization, special tools, or debugging environment.

Example #1 Example of dump() method

  1. Zend_Debug::dump($var, $label = null, $echo = true);

The $var argument specifies the expression or variable about which the Zend_Debug::dump() method outputs information.

The $label argument is a string to be prepended to the output of Zend_Debug::dump(). It may be useful, for example, to use labels if you are dumping information about multiple variables on a given screen.

The boolean $echo argument specifies whether the output of Zend_Debug::dump() is echoed or not. If TRUE, the output is echoed. Regardless of the value of the $echo argument, the return value of this method contains the output.

It may be helpful to understand that Zend_Debug::dump() method wraps the PHP function » var_dump(). If the output stream is detected as a web presentation, the output of var_dump() is escaped using » htmlspecialchars() and wrapped with (X)HTML <pre> tags.

Tip

Debugging with Zend_Log

Using Zend_Debug::dump() is best for ad hoc debugging during software development. You can add code to dump a variable and then remove the code very quickly.

Also consider the Zend_Log component when writing more permanent debugging code. For example, you can use the DEBUG log level and the stream log writer to output the string returned by Zend_Debug::dump().

Previous topic

Zend_Debug

Next topic

Zend_Dojo

Copyright

© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts