php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16179 Multidimensional Arrays works wrong
Submitted: 2002-03-20 05:10 UTC Modified: 2002-03-20 05:32 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: andrej at cybernoidz dot de Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.1.2 OS: Windows 2002
Private report: No CVE-ID: None
 [2002-03-20 05:10 UTC] andrej at cybernoidz dot de
My php-Code:
<?
  $property [ "src" ][ "brett" ] = "DBJ_20020112.db.php";
  $property [ "src" ][ "brett" ][ "entity" ] = "ABrettEntry";

  // ----------------------------------------
  $GLOBALS[ "property" ] = $property;

  echo( "AUSGABE1 ::: ".$property["src"]["brett"]["entity"]."<BR>" );
  echo( "AUSGABE2 ::: ". $property [ "src" ][ "brett" ]."<BR>" );

?>

And the result of this script looks like this:

AUSGABE1 ::: A
AUSGABE2 ::: ABJ_20020112.db.php

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-20 05:26 UTC] mboeren@php.net
You are mixing the number of dimensions in the array... this can lead to strange things indeed.

What I think happens is this: 
In the second assignment, the extra ["entity"] is seen as an index into the string "DBJ...", and since "entity" evaluates to zero, the first character of the string is changed. Because a character is expected, the string "ABrettEntry" is converted to a char, 'A'.

You can see this if you change ["entity"] to [0] (or [1], then it changes the second character).

It is easily circumvented by changing the first assignment to $property [ "src" ][ "brett" ][ "filename" ] = "DBJ_20020112.db.php";

Anyway, I don't think this is a bug in multi-dim-arrays, but perhaps the documentation is not clear? Perhaps this should be reclassified as a documentation problem?

Cheerio, Marc.
 [2002-03-20 05:32 UTC] hholzgra@php.net
the problem is that single character access to strings is still possible using either $string[...] or $string{...},
although using {} is recommended and [] more or less deprecated

so what you did was assigning to the first character in a string ("entity" auto-converts to integer zero), and as a character position can only take a single character it took only the "A" from the newly assigned string

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 09:01:28 2024 UTC