Skip to content

Commit 13685ba

Browse files
author
Martijn Otto
committed
Merge branch 'sjinks-issue261'
2 parents c9b166d + 4831603 commit 13685ba

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

zend/value.cpp

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,12 @@ Value::Value(const IniValue &value) : Value((const char *)value) {}
203203
*/
204204
Value::Value(const Value &that)
205205
{
206-
// copy over the zval
207-
ZVAL_COPY(_val, that._val);
206+
if (Z_ISREF_P(that._val)) {
207+
zend_assign_to_variable(_val, that._val, IS_VAR);
208+
}
209+
else {
210+
ZVAL_COPY(_val, that._val);
211+
}
208212
}
209213

210214
/**
@@ -331,39 +335,7 @@ Value &Value::operator=(const Value &value)
331335
// skip self assignment
332336
if (this == &value) return *this;
333337

334-
// is the object a reference?
335-
if (Z_ISREF_P(_val))
336-
{
337-
// the current object is a reference, this means that we should
338-
// keep the zval object, and copy the other value into it, get
339-
// the current refcount
340-
int refcount = Z_REFCOUNT_P(_val);
341-
342-
// clean up the current zval (but keep the zval structure)
343-
zval_dtor(_val);
344-
345-
// make the copy
346-
*_val = *value._val;
347-
zval_copy_ctor(_val);
348-
349-
// restore refcount and reference setting
350-
ZVAL_MAKE_REF(_val);
351-
Z_SET_REFCOUNT_P(_val, refcount);
352-
}
353-
else
354-
{
355-
// destruct the zval (this function will decrement the reference counter,
356-
// and only destruct if there are no other references left)
357-
zval_ptr_dtor(_val);
358-
359-
// just copy the zval, and the refcounter
360-
_val = value._val;
361-
362-
// and we have one more reference
363-
Z_TRY_ADDREF_P(_val);
364-
}
365-
366-
// update the object
338+
zend_assign_to_variable(_val, value._val, IS_VAR);
367339
return *this;
368340
}
369341

0 commit comments

Comments
 (0)