PHP dump all local variables

Source: Internet
Author: User

Although xdebug is available, log or var_dump is usually used for debugging.

I often want to know the current variable status when executing a certain point. I came back today and found the following information on the PHP Official Website: kailashbaduCodeWrite one.

The core is the get_defined_vars () function. In addition, the get_defined_constants () function is used to retrieve all constants.

 

/*** @ DESC show the variable that are to be excluded from the list. * $ varlist array * $ excludelist array */function logvars ($ varlist, $ excludelist = NULL) {if ($ excludelist = NULL) $ excludelist = array ('globals ', '_ FILES', '_ cookies',' _ Post', '_ get'); $ list = array (); foreach ($ varlist as $ key => $ value) {If (! In_array ($ key, $ excludelist) $ list [$ key] = $ value;} echo '<PRE>'; print_r ($ list ); echo '</PRE>';} // some dummy variables; add your own or include a file. $ firstname = 'kailash '; $ lastname = 'badu'; $ test = array ('pratistha', 'sanu', 'fuchhi'); logvars (get_defined_vars ()); // results/* array ([firstname] => Kailash [lastname] => Badu [test] => array ([0] => pratistha [1] => sanu [2] => fuchhi )) */

 

Reference: http://cn.php.net/manual/en/function.get-defined-vars.php

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.