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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Sat May 25 15:01:27 2019 UTC