php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69172 array_slice behaviour BC in PHP7
Submitted: 2015-03-03 16:22 UTC Modified: 2015-03-04 01:35 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: hdtfonseca at gmail dot com Assigned: reeze (profile)
Status: Closed Package: Arrays related
PHP Version: master-Git-2015-03-03 (Git) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hdtfonseca at gmail dot com
New email:
PHP Version: OS:

 

 [2015-03-03 16:22 UTC] hdtfonseca at gmail dot com
Description:
------------
The array_slice functions seems to being behaving differently in master (PHP7).
 
The attached test script will output differently in PHP < 7

Test script:
---------------
$stack[] = 'wew';
$stack[] = 'wew';
$stack[] = 'wew';
$stack[] = 'wew';
$stack = array_slice($stack, 0, - 2);
$stack[] = 'wew';

print_r($stack);


Expected result:
----------------
Array
(
    [0] => wew
    [1] => wew
    [2] => wew
)

Actual result:
--------------
Array
(
    [0] => wew
    [1] => wew
    [3] => wew
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-03 18:01 UTC] reeze@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: reeze
 [2015-03-03 18:01 UTC] reeze@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

This has been fixed, please try lastest master.
 [2015-03-04 00:24 UTC] hdtfonseca at gmail dot com
Hi, I'm sorry, I couldn't find the commit in master, can you give me a hint?
 [2015-03-04 00:58 UTC] reeze@php.net
See bug #69166
 [2015-03-04 00:58 UTC] yohgaki@php.net
It seems it's fixed. I don't know which commit does, though.

[yohgaki@dev php-src]$ ./php-bin
<?php

$stack[] = 'wew';
$stack[] = 'wew';
$stack[] = 'wew';
$stack[] = 'wew';
$stack = array_slice($stack, 0, - 2);
$stack[] = 'wew';

print_r($stack);

Array
(
    [0] => wew
    [1] => wew
    [2] => wew
)
 [2015-03-04 01:12 UTC] hdtfonseca at gmail dot com
Thanks, I didn't notice that those were related. Shouldn't we add tests for those?
Are the actual/expected results of this both issues enough for a PR to be accepted?
 [2015-03-04 01:35 UTC] reeze@php.net
Yes, I think that fix's test is enough, they are the same root cause. we can't enumerate all of the usage of that case ;-)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 14:01:37 2025 UTC