php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50401 Array Key Data Type Conversion
Submitted: 2009-12-07 20:20 UTC Modified: 2009-12-07 20:25 UTC
From: michael dot patrick dot mcnally at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.3.1 OS: Windows Vista
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: michael dot patrick dot mcnally at gmail dot com
New email:
PHP Version: OS:

 

 [2009-12-07 20:20 UTC] michael dot patrick dot mcnally at gmail dot com
Description:
------------
It is necessary that I check to see if an array key has been set by the code.  Such as is with this code:

foreach($array as $key => $value){

     if(is_int($key)) echo 'the code assigned a key for this element';

}


How can I achieve this with the following array?:

array('1'=>'Yes','0'=>'No');


PHP converts the '1' into 1 which leaves me no detection for user assigned keys.  This is bad form.

Reproduce code:
---------------
---
From manual page: language.types.array
---



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-07 20:25 UTC] rasmus@php.net
This is part of being a dynamically typed language aimed at the Web.  
There are no types in an HTTP request.  Everything comes across as 
strings, or just data, if you will.  PHP tries to make sense of that 
data in the most logical way.  This isn't going to change.

If you need stronger typing, you need to apply some logic on your own 
to achieve that.  Like keep a separate array for user-changeable 
options, for example.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC