php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81160 isset/empty doesn't throw a TypeError on invalid string offset
Submitted: 2021-06-17 22:02 UTC Modified: 2021-06-17 22:03 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: girgias@php.net Assigned: girgias (profile)
Status: Verified Package: Scripting Engine problem
PHP Version: 8.0.8RC1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-06-17 22:02 UTC] girgias@php.net
Description:
------------
An invalid array offset will trigger a TypeError when used in isset/empty.

The same should be done for string offsets.

Test script:
---------------
<?php

$s = 'Hello';
$o = new stdClass();
$a = [];

try {
    var_dump(isset($s[$o]));
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(empty($s[$o]));
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(isset($s[$a]));
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(empty($s[$a]));
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(isset($s[[]]));
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(empty($s[[]]));
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-17 22:03 UTC] girgias@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: girgias
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Aug 01 15:01:24 2021 UTC