summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-12-15 16:59:21 +0000
committerMarcus Boerger <helly@php.net>2003-12-15 16:59:21 +0000
commitd4f64f88badd33ae87b9ec9b3120d532c8352b05 (patch)
treea8830cb4ed9cc2bd3f831980a1dc4d56bd02abee /Zend
parent18096396d2e0d0545946a09087ec633f250b9dfd (diff)
downloadphp-git-d4f64f88badd33ae87b9ec9b3120d532c8352b05.tar.gz
Reenable __tostring() magic for print,echo,concatenation,function naming...
but not for other internal things. # As discussed with Andi
Diffstat (limited to 'Zend')
-rw-r--r--Zend/zend.c11
-rw-r--r--Zend/zend_object_handlers.c34
-rw-r--r--Zend/zend_object_handlers.h3
3 files changed, 42 insertions, 6 deletions
diff --git a/Zend/zend.c b/Zend/zend.c
index 983d46e17b..5dbfb950da 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -227,7 +227,11 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop
case IS_OBJECT:
if (expr->value.obj.handlers->cast_object) {
TSRMLS_FETCH();
- if (expr->value.obj.handlers->cast_object(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) {
+ if (expr->value.obj.handlers->cast_object == zend_std_cast_object) {
+ if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) {
+ break;
+ }
+ } else if (expr->value.obj.handlers->cast_object(expr, expr_copy, IS_STRING, 0 TSRMLS_CC) == SUCCESS) {
break;
}
if (EG(exception)) {
@@ -239,11 +243,6 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop
}
expr_copy->value.str.val = (char *) emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG);
expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", (long)expr->value.obj.handle);
-#if 0
- /* FIXME: This might break BC for some people */
- expr_copy->value.str.len = sizeof("Object")-1;
- expr_copy->value.str.val = estrndup("Object", expr_copy->value.str.len);
-#endif
break;
case IS_DOUBLE:
*expr_copy = *expr;
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index f3ac745484..1528a3fda4 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -888,6 +888,40 @@ int zend_std_object_get_class_name(zval *object, char **class_name, zend_uint *c
return SUCCESS;
}
+ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC)
+{
+ zval fname, *retval;
+ int is_ref, refcount;
+
+ switch (type) {
+ case IS_STRING:
+ ZVAL_STRING(&fname, "__tostring", 0);
+ if (call_user_function_ex(NULL, &readobj, &fname, &retval, 0, NULL, 0, NULL TSRMLS_CC) == SUCCESS) {
+ if (retval) {
+ if (Z_TYPE_P(retval) != IS_STRING) {
+ zend_error(E_ERROR, "Method %s::__toString() must return a string value", Z_OBJCE_P(readobj)->name);
+ }
+ } else {
+ MAKE_STD_ZVAL(retval);
+ ZVAL_STRINGL(retval, empty_string, 0, 0);
+ }
+ zval_dtor(writeobj);
+ is_ref = writeobj->is_ref;
+ refcount = writeobj->refcount;
+ *writeobj = *retval;
+ zval_copy_ctor(writeobj);
+ writeobj->is_ref = is_ref;
+ writeobj->refcount = refcount;
+ zval_ptr_dtor(&retval);
+ return SUCCESS;
+ }
+ break;
+ default:
+ break;
+ }
+ return FAILURE;
+}
+
int zend_std_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC)
{
return FAILURE;
diff --git a/Zend/zend_object_handlers.h b/Zend/zend_object_handlers.h
index 3e98d7713b..9687f05f5a 100644
--- a/Zend/zend_object_handlers.h
+++ b/Zend/zend_object_handlers.h
@@ -118,6 +118,9 @@ union _zend_function *zend_std_get_static_method(zend_class_entry *ce, char *fun
zval **zend_std_get_static_property(zend_class_entry *ce, char *property_name, int property_name_len, zend_bool silent TSRMLS_DC);
zend_bool zend_std_unset_static_property(zend_class_entry *ce, char *property_name, int property_name_len TSRMLS_DC);
+int zend_std_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC);
+ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC);
+
#define IS_ZEND_STD_OBJECT(z) ((z).type == IS_OBJECT && (Z_OBJ_HT((z))->get_class_entry != NULL))
#define HAS_CLASS_ENTRY(z) (Z_OBJ_HT(z)->get_class_entry != NULL)