Req #37676 [Com]: using Array access operator [] on boolean variable does not show Notice

From: Date: Wed, 07 Oct 2015 18:20:27 +0000
Subject: Req #37676 [Com]: using Array access operator [] on boolean variable does not show Notice
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196460@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=37676&edit=1

 ID:                 37676
 Comment by:         codedokode at gmail dot com
 Reported by:        tgross at m-s dot de
 Summary:            using Array access operator [] on boolean variable
                     does not show Notice
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

Also it silently returns NULL when trying to pass a number as an array: 

-------------

<?php
 
error_reporting(E_ALL);
$int = 1;
var_dump($int[100]);

-------------

Expected: Error using integer as array
Actual result: NULL

I thing using a scalar value as an array is obviously user's error and it should be reported,
e.g. with error message.

Tested in PHP 5.6.7 (Debian), no error message reported. 

The same result if we use float instead of int. The same result if we use resource as array:

$ php -r 'error_reporting(-1);$h = fopen("/etc/passwd", "r"); $x =
$h[0];var_dump($x);'
NULL


Previous Comments:
------------------------------------------------------------------------
[2015-06-08 20:51:45] cmb@php.net

Related To: Bug #65484

------------------------------------------------------------------------
[2015-06-08 20:47:51] cmb@php.net

Related To: Bug #40692

------------------------------------------------------------------------
[2015-05-12 21:06:24] cmb@php.net

Related To: Bug #48560

------------------------------------------------------------------------
[2015-01-09 00:41:51] ajf@php.net

Related: https://bugs.php.net/bug.php?id=39915

------------------------------------------------------------------------
[2015-01-09 00:26:14] ajf@php.net

Still exists in PHP 5.6:

$ php -d error_reporting=E_ALL -r '$x = false; var_dump($x[5]);'
NULL

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=37676


--
Edit this bug report at https://bugs.php.net/bug.php?id=37676&edit=1


Thread (11 messages)

« previous php.bugs (#196460) next »