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:2
Avg. Score:2.5 ± 1.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: girgias@php.net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC