cvs: php4 /main output.c
| From: | Marcus B�rger | Date: | Sun, 25 Aug 2002 12:16:49 +0000 |
| Subject: | cvs: php4 /main output.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-13663@lists.php.net to get a copy of this message | ||
helly Sun Aug 25 08:16:49 2002 EDT
Modified files:
/php4/main output.c
Log:
Use zend_is_callable() instead of php_check_object_method_array() and
drop the latter. THX to Markus Fischer - i did not recognize this function.
@Expanded ob_start() to allow object parameters without methodnames and
@use default method __output_handler(). (Marcus)
Index: php4/main/output.c
diff -u php4/main/output.c:1.117 php4/main/output.c:1.118
--- php4/main/output.c:1.117 Sun Aug 25 07:50:25 2002
+++ php4/main/output.c Sun Aug 25 08:16:48 2002
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: output.c,v 1.117 2002/08/25 11:50:25 helly Exp $ */
+/* $Id: output.c,v 1.118 2002/08/25 12:16:48 helly Exp $ */
#include "php.h"
#include "ext/standard/head.h"
@@ -480,34 +480,6 @@
}
/* }}} */
-/* {{{ php_check_object_method_array
- * This function set *name to the 'object->method()' of NULL if given.
- * The callee must free that result using efree() function.
- */
-static int php_check_object_method_array(HashTable *ht, char **name)
-{
- if (zend_hash_num_elements(ht)>1) {
- zval **object, **method;
-
- if (zend_hash_index_find(ht, 0, (void **) &object)!=FAILURE
- && zend_hash_index_find(ht, 1, (void **) &method)!=FAILURE)
- {
- if ((*object)->type == IS_OBJECT
- && (*method)->type == IS_STRING)
- {
- if (*name) {
- spprintf(name, 0, "%s->%s()", Z_OBJCE_PP(object)->name, Z_STRVAL_PP(method));
- }
- return 1;
- }
- }
- }
- if (*name)
- *name = NULL;
- return 0;
-}
-/* }}} */
-
/* {{{ php_ob_init
*/
static int php_ob_init(uint initial_size, uint block_size, zval *output_handler, uint chunk_size,
zend_bool erase TSRMLS_DC)
@@ -546,12 +518,13 @@
else if (output_handler && output_handler->type == IS_ARRAY) {
result = 0;
/* do we have array(object,method) */
- if (php_check_object_method_array(Z_ARRVAL_P(output_handler), &handler_name)) {
+ if (zend_is_callable(output_handler, 1, &handler_name)) {
SEPARATE_ZVAL(&output_handler);
output_handler->refcount++;
result = php_ob_init_named(initial_size, block_size, handler_name, output_handler, chunk_size,
erase TSRMLS_CC);
efree(handler_name);
} else {
+ /* init all array elements recursively */
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(output_handler), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(output_handler), (void **)&tmp, &pos) ==
SUCCESS) {
result &= php_ob_init(initial_size, block_size, *tmp, chunk_size, erase TSRMLS_CC);
@@ -559,6 +532,26 @@
}
}
result = result ? SUCCESS : FAILURE;
+ }
+ else if (output_handler && output_handler->type == IS_OBJECT) {
+ /* use __output_handler if only an object is given */
+ zval *object_method;
+
+ MAKE_STD_ZVAL(object_method);
+ if (array_init(object_method) != FAILURE) {
+ add_next_index_zval(object_method, output_handler);
+ add_next_index_string(object_method, "__output_handler", 1);
+ if (zend_is_callable(object_method, 1, &handler_name)) {
+ object_method->refcount++;
+ result = php_ob_init_named(initial_size, block_size, handler_name, object_method, chunk_size,
erase TSRMLS_CC);
+ efree(handler_name);
+ result = result ? SUCCESS : FAILURE;
+ } else {
+ result = FAILURE;
+ }
+ } else {
+ result = FAILURE;
+ }
}
else {
if (output_handler) {