}
/* }}} */
-ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type) /* {{{ */
+ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type) /* {{{ */
{
- zval retval;
- zend_class_entry *ce;
-
switch (type) {
- case IS_STRING:
- ce = Z_OBJCE_P(readobj);
+ case IS_STRING: {
+ zend_class_entry *ce = readobj->ce;
if (ce->__tostring) {
+ zval retval;
+ zend_class_entry *fake_scope = EG(fake_scope);
+ EG(fake_scope) = NULL;
+ GC_ADDREF(readobj);
zend_call_method_with_0_params(readobj, ce, &ce->__tostring, "__tostring", &retval);
+ zend_object_release(readobj);
+ EG(fake_scope) = fake_scope;
if (EXPECTED(Z_TYPE(retval) == IS_STRING)) {
ZVAL_COPY_VALUE(writeobj, &retval);
return SUCCESS;