Req #72636 [Opn->Dup]: Offset access should trigger error for integers and bools

From: Date: Thu, 21 Jul 2016 14:14:24 +0000
Subject: Req #72636 [Opn->Dup]: Offset access should trigger error for integers and bools
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202480@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72636&edit=1 ID: 72636 Updated by: cmb@php.net Reported by: david at grudl dot com Summary: Offset access should trigger error for integers and bools -Status: Open +Status: Duplicate Type: Feature/Change Request Package: Scripting Engine problem PHP Version: Next Minor Version -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Duplicate of request #37676. Previous Comments: ------------------------------------------------------------------------ [2016-07-20 21:05:26] david at grudl dot com Description: ------------ Invalid offset access triggers some kind of errors for strings (and of course arrays): $str = 'abc'; echo $str[TRUE]; // Notice: String offset cast occurred echo $str[NULL]; // Notice: String offset cast occurred echo $str[[]]; // Warning: Illegal offset type But it triggers no error when variable is integer, float or bool, which is inconsistent: $int = 123; echo $int[1]; // no error echo $int[TRUE]; // no error echo $int[[]]; // no error Test script: --------------- https://3v4l.org/JCXR1 <?php $str = 'abc'; echo $str[TRUE]; // Notice: String offset cast occurred echo $str[NULL]; // Notice: String offset cast occurred echo $str[[]]; // Warning: Illegal offset type $int = 123; echo $int[1]; // no error echo $int[TRUE]; // no error echo $int[[]]; // no error $bool = TRUE; echo $bool[1]; // no error echo $bool[TRUE]; // no error echo $bool[[]]; // no error Expected result: ---------------- trigger errors ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72636&edit=1

« previous php.bugs (#202480) next »