php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76114 unset deletes too much
Submitted: 2018-03-19 10:41 UTC Modified: 2018-06-24 04:25 UTC
From: hgalt at gmx dot net Assigned:
Status: No Feedback Package: opcache
PHP Version: 7.2.3 OS: server 2012 R2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hgalt at gmx dot net
New email:
PHP Version: OS:

 

 [2018-03-19 10:41 UTC] hgalt at gmx dot net
Description:
------------
When I use unset to dele a specific array inside an array, it deletes the specific array and all array  on the same level behind this specific array.

My structure:
*0: 0: id -> 0
	1: name -> Teig
	2: doing -> 
	*3: 0: q -> 100
		1: u -> g
		2: p -> wheat_flour
	*4: 1:  q -> 100
		1: u -> g
		2: p -> sugar
	*5: 2: q -> 100
		1: u -> g
		2: p -> milk
1: count -> 1
2: uidR -> 2

The star infront of the key says that it is an array.

If I execute 
unset($array[0][1]);
the array *4 will be deleted but also the next one (*5). If after *5 additional arrays would be follow, these would be also deleted.

I know, that in the past this was working, but I am sorry, I don't know when.



Test script:
---------------
<?php

$array [0]= ['id' => 0, 'name' => 'Teig', 'doing' => 'Test'];
$array[0][0] = ['q' => '100', 'u' => 'g', 'p' => 'wheat_flour'];
$array[0][1] = ['q' => '100', 'u' => 'g', 'p' => 'sugar'];
$array[0][2] = ['q' => '100', 'u' => 'g', 'p' => 'milk'];
$array[] = ['count' => '1', 'uidR' => '2'];

unset($array[0][1]);

Expected result:
----------------
*0: 0: id -> 0
	1: name -> Teig
	2: doing -> 
	*3: 0: q -> 100
		1: u -> g
		2: p -> wheat_flour
	*5: 2: q -> 100
		1: u -> g
		2: p -> milk
1: count -> 1
2: uidR -> 2

Actual result:
--------------
*0: 0: id -> 0
	1: name -> Teig
	2: doing -> 
	*3: 0: q -> 100
		1: u -> g
		2: p -> wheat_flour
1: count -> 1
2: uidR -> 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-19 10:47 UTC] spam2 at rhsoft dot net
these "structures" are a total mess
why don't you just use print_r() so that it becomes readable?

php > print_r($x);
Array
(
    [1] => Array
        (
            [1] => x
            [2] => y
            [3] => Array
                (
                    [0] => a
                    [1] => b
                )

        )

    [2] => Array
        (
            [0] => x
        )

)
 [2018-03-19 10:47 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-03-19 10:47 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Looks fine to me. https://3v4l.org/6iVoU

Are you sure this is related to opcache? What if you turn off optimizations?
 [2018-06-24 04:25 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Jan 26 06:01:23 2020 UTC