PHP variable debugging function-PHP source code

Source: Internet
Author: User
PHP variable debugging functions

[PHP] code
function ss_array_as_string (&$array, $column = 0) {$str = "Array(n";while(list($var, $val) = each($array)){for ($i = 0; $i < $column+1; $i++){$str .= "    ";}$str .= $var. '==>' ;$str .= ss_as_string($val, $column+1)." n";}for ($i = 0; $i < $column; $i++){$str .= "    ";}return $str.);}function ss_object_as_string (&$object, $column = 0) {if (empty($object->classname)) {return "$object";}  else {$str = $object->classname."( n";while (list(,$var) = each($object->persistent_slots)) {for ($i = 0; $i < $column; $i++){$str .= "    ";}   global $$var;   $str .= $var. '==>' ;$str .= ss_as_string($$var, column+1)." n";}for ($i = 0; $i < $column; $i++){$str .= "    ";}return $str.')';}}function ss_as_string (&$thing, $column = 0) {if (is_object($thing)) {return ss_object_as_string($thing, $column);} elseif (is_array($thing)) {return ss_array_as_string($thing, $column);} elseif (is_double($thing)) {return "Double(".$thing.")";}  elseif (is_long($thing)) {return "Long(".$thing.")";}  elseif (is_string($thing)) {return "String(".$thing.")";}  else {return "Unknown(".$thing.")";}}

When necessary, simply add the following code to the program to view the types and values of the variables used in the program (including arrays and objects ).

echo ss_as_string($my_variable);

Using the following statement, we can directly view the values of all the variables in the program

echo ss_as_string($GLOBALS);

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.