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

From: Date: Mon, 25 Jul 2016 17:35:58 +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-202588@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:         dave at mudsite 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:

I attached a PR to this issue.  It attempts to only display an E_NOTICE once for extended failures
like:

$a = false;
$a[1][2][3][4];

This should error once.  It will also raise an E_NOTICE for other FETCH_DIM_R opcodes like:

$a = false;
list($b, $c) = $a;

This would have 2 E_NOTICE one for each assignment to $b, and $c.


Previous Comments:
------------------------------------------------------------------------
[2016-07-21 14:14:23] cmb@php.net

Related To: Bug #72636

------------------------------------------------------------------------
[2015-10-07 18:20:25] codedokode at gmail dot com

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

------------------------------------------------------------------------
[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

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


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 (#202588) next »