php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69017 Fail to push to the empty array with the constant value defined in class scope
Submitted: 2015-02-09 07:35 UTC Modified: 2015-02-11 17:58 UTC
Votes:6
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:5 (100.0%)
Same OS:2 (40.0%)
From: n-hatano at infiniteloop dot co dot jp Assigned: reeze
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.37 OS: any
Private report: No CVE-ID:
 [2015-02-09 07:35 UTC] n-hatano at infiniteloop dot co dot jp
Description:
------------
Failed to push to the empty array with the constant value zero defined in class scope.

We were able to push any value using empty square bracket to the array which has initialized in class definition.

However, if we use the php 5.4.34 - 5.4.37, 5.5.18 - 5.5.21,
the following message has returned and the php fails to push the value.
 
"Warning: Cannot add element to the array as the next element is already occupied in"


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

class c1
{
  const ZERO = 0;
  const ONE = 1;
  public static $a1 = array(self::ONE => 'one');
  public static $a2 = array(self::ZERO => 'zero');
}

$v1 = c1::$a1;
$v2 = c1::$a2;

$v1[] = 1;
$v2[] = 1;

var_dump($v1);
var_dump($v2);

Expected result:
----------------
array(2) {
  [1]=>
  string(3) "one"
  [2]=>
  int(1)
}
array(2) {
  [0]=>
  string(4) "zero"
  [1]=>
  int(1)
}


Actual result:
--------------
array(2) {
  [1]=>
  string(3) "one"
  [0]=>
  int(1)
}
array(1) {
  [0]=>
  string(4) "zero"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-10 00:32 UTC] n-hatano at infiniteloop dot co dot jp
-Operating System: +Operating System: any
 [2015-02-10 00:32 UTC] n-hatano at infiniteloop dot co dot jp
It seems this bug must be seen on any os.
 [2015-02-10 01:53 UTC] yohgaki@php.net
-Status: Open +Status: Verified
 [2015-02-10 02:24 UTC] yohgaki@php.net
-Package: Arrays related +Package: Scripting Engine problem
 [2015-02-10 02:24 UTC] yohgaki@php.net
It seems $a2 initialization is broken at compile time.
 [2015-02-10 02:26 UTC] yohgaki@php.net
Correction. It should be execution time.
 [2015-02-11 17:58 UTC] reeze@php.net
-Assigned To: +Assigned To: reeze
 [2015-02-12 00:49 UTC] reeze@php.net
This patch should be able to fix the bug: https://github.com/php/php-src/pull/1077
 [2015-02-12 03:25 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f2940b7120a0dc77ccfaacceed04faaa68b4dc23
Log: Fixed bug #69017 (Fail to push to the empty array with the constant value defined in class scope)
 [2015-02-12 03:25 UTC] laruence@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Apr 25 00:01:35 2017 UTC