php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81159 Object to int warning when using an object as a string offset
Submitted: 2021-06-17 21:59 UTC Modified: 2021-06-17 22:01 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: girgias@php.net Assigned: girgias (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 8.0.8RC1 OS:
Private report: No CVE-ID: None
 [2021-06-17 21:59 UTC] girgias@php.net
Description:
------------
As of PHP 8.0 objects cannot be used as string offsets, but they still emit an E_WARNING about conversion to int on top of the TypeError

Test script:
---------------
<?php
$s = 'Hello';
$o = new stdClass();
try {
    $s[$o] = 'A';
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($s[$o]);
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
?>

Expected result:
----------------
Cannot access offset of type stdClass on string
Cannot access offset of type stdClass on string

Actual result:
--------------
Warning: Object of class stdClass could not be converted to int in /in/YhEYe on line 11
Cannot access offset of type stdClass on string

Warning: Object of class stdClass could not be converted to int in /in/YhEYe on line 16
Cannot access offset of type stdClass on string

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-17 22:01 UTC] girgias@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: girgias
 [2021-06-18 17:12 UTC] git@php.net
Automatic comment on behalf of Girgias
Revision: https://github.com/php/php-src/commit/f0fd5922eeb735811f0da0458c390178ceb425ec
Log: Fix bug #81159: Object to int warning when using an object as a string offset
 [2021-06-18 17:12 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 17 20:03:37 2021 UTC