php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #7569 Transmuting indices
Submitted: 2000-11-01 11:46 UTC Modified: 2001-06-27 10:21 UTC
From: ignacio at openservices dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0 Latest CVS (01/11/2000) OS: Red Hat Linux 6.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ignacio at openservices dot net
New email:
PHP Version: OS:

 

 [2000-11-01 11:46 UTC] ignacio at openservices dot net
(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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-01 12:18 UTC] waldschrott@php.net
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 12:48 UTC] ignacio at openservices dot net
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 13:41 UTC] ignacio at openservices dot net
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 19:54 UTC] waldschrott@php.net
please place this in front of that print_r()
a) var_dump($kind);
b) var_dump($row1);

and append the output here
 [2000-11-01 22:44 UTC] ignacio at openservices dot net
Ah, I see now. What I initially thought was "" is in fact false. It seems that NULLs in MS-SQL are converted to falses in Sybase-CT under PHP. Lovely.

Well, changing the ""/0 to false in the generation segment fixed the code and explains the problems. Now all we need is for somebody to document this NULL=>false fact. And some documentation about the Boolean type might be appreciated as well :)
 [2000-11-02 06:39 UTC] waldschrott@php.net
I can?t verify if mssql functions are wrong, it?s not
installed here, every function decides itself how to convert
or not to convert, but basically these 4 are not equivalent

$row=array(1=>NULL,2=>FALSE,3=>"\0",4=>"");
var_dump($row);

I agree, the docs could need some update on these (eg. NULL)
and boolean types (resource type too)
 [2000-11-03 14:45 UTC] joey@php.net
Either false or NULL is the only sane thing for PHP to get
in such a case. "" *is not* the same as null, they are
very different from the DB's point of view. I think perhaps
this one should be closed, but will defer to anyone who feels
really strongly one way or the other.
 [2001-06-26 23:59 UTC] danbeck@php.net
Not really a documentation issue.  Using NULL fields in a database is just bad... but I'm a doc writer.. so take it for what it's worth.
 [2001-06-27 10:21 UTC] ignacio at openservices dot net
There are two documentation issues here:

1) Nowhere in the documentation does it talk about the Boolean type.

2) Nowhere in the documentation does it say that NULL values from a database become False in PHP. NULL happens, for better or worse.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 14 15:00:01 2026 UTC