]> granicus.if.org Git - php/commitdiff
- Added parameter to print_r which returns the variable representation
authorDerick Rethans <derick@php.net>
Thu, 25 Jul 2002 11:22:20 +0000 (11:22 +0000)
committerDerick Rethans <derick@php.net>
Thu, 25 Jul 2002 11:22:20 +0000 (11:22 +0000)
  instead of echoing it.
@- Added parameter to print_r which returns the variable representation
@  instead of echoing it. (Derick)

ext/standard/basic_functions.c

index 633f2cb0df58e20310c434cf1bfa7a40ebbe153f..67f5958b1aa44e92764240824849416768526aa1 100644 (file)
@@ -2077,19 +2077,29 @@ PHP_FUNCTION(ini_restore)
 }
 /* }}} */
 
-/* {{{ proto bool print_r(mixed var)
-   Prints out information about the specified variable */
+/* {{{ proto bool print_r(mixed var [, bool return])
+   Prints out or returns information about the specified variable */
 PHP_FUNCTION(print_r)
 {
-       pval **expr;
+       zval *var;
+       zend_bool i = 0;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &expr) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &var, &i) == FAILURE) {
+               return;
+       }
+       
+       if (i) {
+               php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
        }
 
-       zend_print_pval_r(*expr, 0);
+       zend_print_pval_r(var, 0);
 
-       RETURN_TRUE;
+       if (i) {
+               php_ob_get_buffer (return_value TSRMLS_CC);
+               php_end_ob_buffer (0, 0 TSRMLS_CC);
+       } else {
+               RETURN_TRUE;
+       }
 }
 /* }}} */