|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2015-06-28 05:20 UTC] stas@php.net
 Description:
------------
When applying assign-operator (like +=) to result of $a[] when $a is an object implementing ArrayAccess, segfault happens.
Test script:
---------------
<?php
class C10 implements ArrayAccess
{
        function offsetExists($offset)
        {
                echo "\nInside " . __METHOD__ . "\n"; var_dump($offset);
        }
        function offsetGet($offset)
        {
                echo "\nInside " . __METHOD__ . "\n"; var_dump($offset); return 100;
        }
        function offsetSet($offset, $value)
        {
                echo "\nInside " . __METHOD__ . "\n"; var_dump($offset); var_dump($value);
        }
        function offsetUnset($offset)
        {
                echo "\nInside " . __METHOD__ . "\n"; var_dump($offset);
        }
}
$c10 = new C10;
var_dump($c10[] += 5);
Expected result:
----------------
No segfault
Actual result:
--------------
Inside C10::offsetGet
NULL
Segmentation fault: 11
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
seems we should always have this: diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 933be83..be9b012 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -804,13 +804,11 @@ ZEND_VM_HELPER_EX(zend_binary_assign_op_dim_helper, VAR|UNUSED|CV, CONST|TMPVAR| if (OP1_TYPE != IS_UNUSED) { ZVAL_DEREF(container); } -#if !defined(ZEND_VM_SPEC) || (OP2_TYPE != IS_UNUSED) if (OP1_TYPE == IS_UNUSED || EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { value = get_zval_ptr((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data1 , BP_VAR_R); zend_binary_assign_op_obj_dim(container, dim, value, UNEXPECTED(RETURN_VALUE_USED(opline )) ? EX_VAR(opline->result.var) : NULL, binary_op); break; } -#endif } thanks