cvs: php4 /ext/overload README overload.c
| From: | Andrei Zmievski | Date: | Mon, 10 Dec 2001 17:20:05 +0000 |
| Subject: | cvs: php4 /ext/overload README overload.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-8564@lists.php.net to get a copy of this message | ||
andrei Mon Dec 10 12:20:05 2001 EDT
Modified files:
/php4/ext/overload README overload.c
Log:
Modified __call() handler to accept a byref return value parameter that
should be filled in. The __call() handler is now supposed to return true
or false, depending on whether it was successful or not.
Index: php4/ext/overload/README
diff -u php4/ext/overload/README:1.3 php4/ext/overload/README:1.4
--- php4/ext/overload/README:1.3 Sat Dec 8 23:31:33 2001
+++ php4/ext/overload/README Mon Dec 10 12:20:04 2001
@@ -42,10 +42,11 @@
return true;
}
- function __call($method, $args)
+ function __call($method, $args, &$return_value)
{
print '-- OO::' . $method . "() was called.--\n";
- return call_user_func_array(array(&$this, 'my_' . $method), $args);
+ $return_value = call_user_func_array(array(&$this, 'my_' . $method), $args);
+ return true;
}
function my_whatever($f1, $f2, $f3)
Index: php4/ext/overload/overload.c
diff -u php4/ext/overload/overload.c:1.9 php4/ext/overload/overload.c:1.10
--- php4/ext/overload/overload.c:1.9 Sun Dec 9 17:39:24 2001
+++ php4/ext/overload/overload.c Mon Dec 10 12:20:04 2001
@@ -52,8 +52,6 @@
ZEND_DECLARE_MODULE_GLOBALS(overload)
-/* static int le_overload; */
-
function_entry overload_functions[] = {
PHP_FE(overload, NULL)
{NULL, NULL, NULL}
@@ -181,14 +179,14 @@
return 1;
}
+ zval_ptr_dtor(&retval);
+ zval_dtor(result_ptr);
+
if (zend_hash_index_find(&OOG(overloaded_classes), (long)Z_OBJCE_P(object),
(void*)&oo_data) == FAILURE) {
php_error(E_WARNING, "internal problem trying to get property");
return 0;
}
- zval_ptr_dtor(&retval);
- zval_dtor(result_ptr);
-
if (!oo_data.handle_property_get) {
return 0;
}
@@ -243,13 +241,13 @@
return 1;
}
+ zval_ptr_dtor(&retval);
+
if (zend_hash_index_find(&OOG(overloaded_classes), (long)Z_OBJCE_P(object),
(void*)&oo_data) == FAILURE) {
php_error(E_WARNING, "internal problem trying to set property");
return 0;
}
- zval_ptr_dtor(&retval);
-
if (!oo_data.handle_property_set) {
return 0;
}
@@ -451,8 +449,9 @@
}
if (use_call_handler) {
- zval **handler_args[2];
+ zval **handler_args[3];
zval *arg_array;
+ zval result, *result_ptr = &result;
zend_class_entry temp_ce, *orig_ce;
int i;
@@ -472,23 +471,38 @@
zval_add_ref(args[i]);
add_next_index_zval(arg_array, *args[i]);
}
+
+ result_ptr->is_ref = 1;
+ result_ptr->refcount = 1;
+ ZVAL_NULL(result_ptr);
handler_args[0] = &method_name_ptr;
handler_args[1] = &arg_array;
+ handler_args[2] = &result_ptr;
call_result = call_user_function_ex(NULL,
&object,
&call_handler,
&retval,
- 2, handler_args,
+ 3, handler_args,
0, NULL TSRMLS_CC);
Z_OBJCE_P(object) = orig_ce;
zval_ptr_dtor(&arg_array);
if (call_result == FAILURE || !retval) {
efree(args);
+ zval_dtor(result_ptr);
php_error(E_WARNING, "unable to call %s::" CALL_HANDLER "() handler",
Z_OBJCE_P(object)->name);
return;
}
+
+ if (zval_is_true(retval)) {
+ *return_value = *result_ptr;
+ INIT_PZVAL(return_value);
+ } else {
+ zval_dtor(result_ptr);
+ php_error(E_WARNING, "Call to undefined method %s::%s()", Z_OBJCE_P(object)->name,
Z_STRVAL(method_name));
+ }
+ zval_ptr_dtor(&retval);
} else {
ZVAL_STRINGL(&call_handler, Z_STRVAL(method->element), Z_STRLEN(method->element), 0);
call_result = call_user_function_ex(NULL,
@@ -503,11 +517,12 @@
php_error(E_WARNING, "unable to call %s::%s() method", Z_OBJCE_P(object)->name,
Z_STRVAL(method->element));
return;
}
- }
- *return_value = *retval;
- INIT_PZVAL(return_value);
- FREE_ZVAL(retval);
+ *return_value = *retval;
+ INIT_PZVAL(return_value);
+ FREE_ZVAL(retval);
+ }
+
efree(args);
zval_dtor(&method->element);
}