今天在使用var_export函数时, 竟然有点手生的感觉, 于是把源码翻出来看了看
/* {{{ proto mixed var_export(mixed var [, bool return])
Outputs or returns a string representation of a variable */
PHP_FUNCTION(var_export)
{
zval *var;
zend_bool return_output = 0;
smart_str buf = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &var, &return_output) == FAILURE) {
return;
}
php_var_export_ex(&var, 1, &buf TSRMLS_CC); //把数组当字符串遍历组合出来
smart_str_0 (&buf); //给字符串的最后添加'\0';
if (return_output) {
RETVAL_STRINGL(buf.c, buf.len, 1); //返回给php脚本使用
} else {
PHPWRITE(buf.c, buf.len); //输出
}
smart_str_free(&buf);
}
/* }}} */