php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72636 Offset access should trigger error for integers and bools
Submitted: 2016-07-20 21:05 UTC Modified: 2016-07-21 14:14 UTC
From: david at grudl dot com Assigned: cmb (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: Next Minor Version 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: david at grudl dot com
New email:
PHP Version: OS:

 

 [2016-07-20 21:05 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-21 14:14 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-07-21 14:14 UTC] cmb@php.net
Duplicate of request #37676.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC