#37230 [Opn->Bgs]: array index of type variant fail
| From: | mike@php.net | Date: | Sat, 29 Apr 2006 11:31:28 +0000 |
| Subject: | #37230 [Opn->Bgs]: array index of type variant fail | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-96355@lists.php.net to get a copy of this message | ||
ID: 37230
Updated by: mike@php.net
Reported By: teveritt22 at te-server dot org
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Windows
PHP Version: 5.1.2
New Comment:
No bug.
Previous Comments:
------------------------------------------------------------------------
[2006-04-29 11:31:06] mike@php.net
This is not really realted to the other mentioned bug AFAICS.
It actually is expected behaviour, you should not use non-scalars as
array index (objects, resources etc.).
------------------------------------------------------------------------
[2006-04-28 02:54:44] teveritt22 at te-server dot org
Description:
------------
When using a variant (e.g. new VARIANT(3)) as an index for an array, it
generates "Warning: Illegal offset type". I looked around and not sure
if this is a bug or is expected behavior, but the only way to get
around it is to convert the variant into an integer (e.g sprintf).
In addition, print_r of the variant returns "variant Object #" as
explained in PHP Bug #35956. Bug #35956 states that downloading the
latest PHP solves the issue, however, the issue is still seen with the
latest php version.
Reproduce code:
---------------
<?php
$v = new VARIANT(3);
print "The value is " . $v . "<br/>";
$arry =
array("first","second","third","fourth","fifth");
echo $arry[$v] . "<br/>"; // This does not work
echo print_r($v) . "<br/>"; // This does not work
$v = 3;
echo $arry[$v]. "<br/>"; // This works
$v = new VARIANT(3);
echo $arry[sprintf($v)]; // This works
?>
Expected result:
----------------
The value is 3
fourth
fourth
fourth
fourth
Actual result:
--------------
The value is 3
Warning: Illegal offset type in C:\Documents and
Settings\teveritt\Desktop\online classes
demos\sqlserver\moodle-latest-15\moodle\test.php on line 7
variant Object 1
fourth
fourth
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37230&edit=1