php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73980 PHP error reporting is less strict for bools access as array than for arrays
Submitted: 2017-01-23 14:36 UTC Modified: 2017-01-23 16:08 UTC
From: benp at yelp dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.1.1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: benp at yelp dot com
New email:
PHP Version: OS:

 

 [2017-01-23 14:36 UTC] benp at yelp dot com
Description:
------------
This is well-known from long-past bugs e.g. https://bugs.php.net/bug.php?id=41195, but it really should be reconsidered at some point for future language versions.

It's pretty nuts that undefined offset access is more strict for arrays than it is for booleans (and other objects). Booleans should probably be able to complain about being accessed as arrays.

Test script:
---------------
<?php 
error_reporting(E_ALL);
$boolean = true;
$array = [];
$boolean['hello']; // No error
$array['hello'];  // E_NOTICE

Expected result:
----------------
$boolean['hello'] should throw some error.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-23 16:08 UTC] requinix@php.net
-Status: Open +Status: Duplicate -Package: PHP Language Specification +Package: Scripting Engine problem
 [2017-01-23 16:08 UTC] requinix@php.net
Already considered and accepted, and while it's mostly implemented there are some issues to address.
https://wiki.php.net/rfc/notice-for-non-valid-array-container
https://github.com/php/php-src/pull/2031
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 16:01:24 2020 UTC