php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37230 array index of type variant fail
Submitted: 2006-04-28 02:54 UTC Modified: 2006-04-29 11:31 UTC
From: teveritt22 at te-server dot org Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.1.2 OS: Windows
Private report: No CVE-ID: None
 [2006-04-28 02:54 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-29 11:31 UTC] 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-29 11:31 UTC] mike@php.net
No bug.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 23:00:03 2025 UTC