Php 5.3 Array Compatibility

In php 5.3, the methods for handling arrays are changed.

Array example:

<?php $a = array ('foo' => 1, 'bar' => 2, 'foo' => 3); ?>

use to label 'foo' with the last in the array to give:

array(
    'foo' => 3,
    'bar' => 2
)

now in 5.3 it returns

array(
    'foo' => 1,
    'bar' => 2
)

I am testing php v5.2.11, so I cannot verify this myself. This example is on the php.net website : http://php.net/manual/en/language.types.array.php and find the page for 5.3

there would be a method of setting values ​​through

<?php
    $a['foo'] = 1;
    $a['bar'] = 2;
    $a['foo'] = 3;
?>

provide a feedback compatible patch for this problem? are there any other things to consider when working with arrays in the new php version?

+5
source share
3 answers

:

, , , .

, - PHP (), - , .

, , . , , , , , , .

: @ sberry2A , PHP 5.3 (.. , ).

class Foo
{
  const A = 1;
  const B = 1;

  public static $bar = array(self::A => 1, self::B => 2);
}

, Foo::$bar[1] 2, 1. , :

class Foo
{
  const A = 1;
  const B = 1;

  public static function bar()
  {
    return array(self::A => 1, self::B => 2);
  }
}

, . PHP 5.3.3, , , , ... , .

+2

I think you should use unique keys for the array.

<?php $a = array ('foo' => 1, 'bar' => 2); ?>

Then update the foo value.

<?php $a['foo'] = 3; ?>
0
source