Arbit - project tracking

Dwoo

#63: Array indices containing "." don't work

Issue revisions

  • new by gunigugu at 2010-M-16 11:00
Type bug bug
State new new
Priority normal normal
Resolution none none
Assigned to Nobody
Scheduled for
Affected versions 1.1.1
Affected components Core
Last change Tuesday 16 March 2010 11:00:54 UTC by gunigugu

Short description

Tryed to access an array through it's index, the array didn't find the index although it's there. (similar to: http://bugs.dwoo.org/dwoo/bugs/issue/44/)

Environment

...

Steps to reproduce

$dwoo->assign('myArray', array('ab.cd' => 123, 'efg' => 456)); $dwoo->assign('myIndex', 'ab.cd');

{var_dump $myArray[$myIndex]}

Expected behavior

{var_dump $myArray[$myIndex]} => int 123

{var_dump $myIndex} => string 'ab.cd' (length=5) {var_dump $myArray['ab.cd']} => int 123

Actual behavior

{var_dump $myArray[$myIndex]} => null

{var_dump $myIndex} => string 'ab.cd' (length=5) {var_dump $myArray['ab.cd']} => int 123

  • Jordi Boggiano at Tuesday 16 March 2010 17:29:46 UTC

    This is really tricky to fix, considering the parsing happens at runtime when you have variable variables. I will have a look at how I do it again maybe I have a better idea now than I did when I first wrote it, but I would advise you to just avoid using dots in keys as much as possible until then.

  • char101 at Thursday 30 December 2010 08:32:21 UTC

    I just found this bug. Here's an alternative way

    create this plugin

    arrget.php:

    <?php
    
    function Dwoo_Plugin_arrget(Dwoo $dwoo, $arr)
    {
          $args = func_get_args();
          for ($i = 2, $n = count($args); $i < $n; ++$i) {
                  if (isset($arr[$args[$i]])) {
                          $arr = $arr[$args[$i]];
                  } else {
                          return null;
                  }
          }
          return $arr;
    }
    
    

    In the template:

    {arrget($myArray, $myIndex)}