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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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: Thu Nov 21 11:01:29 2024 UTC