php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38165 no error to return non-existent index of a non-array variable
Submitted: 2006-07-20 15:58 UTC Modified: 2006-07-21 08:50 UTC
From: aurelien dot riche at ac-lille dot fr Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.4 OS: linux
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: aurelien dot riche at ac-lille dot fr
New email:
PHP Version: OS:

 

 [2006-07-20 15:58 UTC] aurelien dot riche at ac-lille dot fr
Description:
------------
There's no error reporting for this code below...
'index' is interpreted as 1 and the value returned is the first letter of string 'hello world'
If it's a normal behavior, can you specify this in the documentation ?


Reproduce code:
---------------
$var = 'hello world';

echo $var['index'];

echo '<br/><br/>';

if(isset($var['index']))
  echo 'OK';

Expected result:
----------------
Notice: Undefined offset: 'index'

Actual result:
--------------
h

OK

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-20 16:00 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

$var[0] is perfectly valid and 'index' is autoconverted to 0.
 [2006-07-21 07:11 UTC] aurelien dot riche at ac-lille dot fr
OK thanks.
I suppose I should do this test instead of before:

if(is_array($var['index']))
  echo 'OK';
 [2006-07-21 08:50 UTC] aurelien dot riche at ac-lille dot fr
Sorry, this test instead of above :

if(is_array($var) && isset($var['index']))
  echo 'OK';
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 21 12:00:03 2025 UTC