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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 + 32 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC