[PHP-DEV] PHP 4.0 Bug #7569 Updated: Transmuting indices From: waldschrott <email protected>
Date: 11/01/00

ID: 7569
Updated by: waldschrott
Reported By: ignacio <email protected>
Status: Feedback
Bug Type: Scripting Engine problem
Assigned To:
Comments:

please place this in front of that print_r()
a) var_dump($kind);
b) var_dump($row1);

and append the output here

Previous Comments:
---------------------------------------------------------------------------

[2000-11-01 13:41:26] ignacio <email protected>
Changing the code so that 0 is used in place of "" when generating $kind allows the code to run correctly, but it does not solve the problem.

---------------------------------------------------------------------------

[2000-11-01 12:48:28] ignacio <email protected>
Well, you see, I can't reproduce it without database code. Here's a smaller version that emulates the data structures:

"""
<?php
$row1=Array(
  0 => "Advertising Space",
  "KindNm" => "Advertising Space",
  1 => "",
  "SubKindNm" => "",
  2 => "",
  "SubSubKindNm" => "",
  3 => 100,
  "GrantKindID" => 100
);

$kind=Array(
  "Advertising Space" => Array(
    "" => Array(
      0 => 100,
      1 => 160
    )
  )
);

print("<pre>");
print_r($kind[$row1["KindNm"]][$row1["SubKindNm"]]);
print("</pre>");
?>
"""

The problem: it works perfectly.

Here's the actual trouble code:

"""
<?php
  error_reporting(2047);
...
while ($row1=mssql_fetch_array($result1))
{
  $val=$row1["GrantKindID"];
    if (empty($row1["SubSubKindNm"]))
  {
    print_r($kind[$row1["KindNm"]][$row1["SubKindNm"]]);
    if (isset($kind[$row1["KindNm"]][$row1["SubKindNm"]]))
    {
      $k=$kind[$row1["KindNm"]][$row1["SubKindNm"]];
      $val=$k[0].":".$k[1];
    };
  };
?>
        <option value="<?=$val?>"><?=$val?></option>
<?php
};
?>
"""

$kind is also much larger than the small one given above, but I'm not convinced that that has anything to do with this problem.

---------------------------------------------------------------------------

[2000-11-01 12:18:29] waldschrott <email protected>
Please provide a reduced code fragment (<15 lines) producing
this behaviour.
Put no database queries etc. in it to ensure that we can
reproduce it easily.

---------------------------------------------------------------------------

[2000-11-01 11:46:51] ignacio <email protected>
(FYI: actually using 2000.10.27 CVS)

Here's a good one.

I have an array $kind:
"""
Array
(
    [Advertising Space] => Array
        (
            [] => Array
                (
                    [0] => 100
                    [1] => 160
                )

        )
 ...
)
"""

I pull a record ($row1) from an MS-SQL table (via Sybase-CT):
"""
Array
(
    [0] => Advertising Space
    [KindNm] => Advertising Space
    [1] =>
    [SubKindNm] => // This is a null string: ""; strlen() gives 0
    [2] =>
    [SubSubKindNm] =>
    [3] => 100
    [GrantKindID] => 100
)
"""

I then do a 'print_r($kind[$row1["KindNm"]][$row1["SubKindNm"]]);':
"""
<br>
<b>Warning</b>: Undefined offset: 0 in <b>/path/to/script/script.php3</b> on line <b>(line with print_r)</b><br>
"""

I know that it's the second index because 'print_r($kind[$row1["KindNm"]]);' works just fine.

So somewhere along the line "" is being changed to 0.

---------------------------------------------------------------------------

Full Bug description available at: http://bugs.php.net/?id=7569

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>