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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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: Wed Dec 04 08:01:29 2024 UTC