php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70835 array cast returns unusable index
Submitted: 2015-11-02 11:34 UTC Modified: 2016-08-08 12:13 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpbugs at elygor dot de Assigned: cmb (profile)
Status: Duplicate Package: Arrays related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpbugs at elygor dot de
New email:
PHP Version: OS:

 

 [2015-11-02 11:34 UTC] phpbugs at elygor dot de
Description:
------------
Converting a stdClass object with (array) behaves different than get_object_vars()

I tested this with PHP 5.4.45 5.5.18 and 5.6.2

Test script:
---------------
$tmp = json_decode(json_encode(
    (object) array('cars' => (object) array("1" => "one"))
));

// expected $cars = array("1" => "one");
$cars = (array) $tmp->cars;

var_dump(array_key_exists("1", $cars)); // expected true, returns false
var_dump(array_key_exists(1, $cars)); // expected true, returns false

$cars = get_object_vars($tmp->cars);

var_dump(array_key_exists("1", $cars)); // expected true, returns true
var_dump(array_key_exists(1, $cars)); // expected true, returns true


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-23 23:35 UTC] ajf@php.net
It's even worse in PHP 7: get_object_vars() also produces an array with inaccessible indices.
 [2016-02-02 05:32 UTC] sagar at aspl dot in
get_object_vars in php7 also produces an array with in-accessible indices
 [2016-08-08 12:13 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-08-08 12:13 UTC] cmb@php.net
I'm marking this as duplicate of bug #71208, because the other
ticket is already assigned.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 16:01:28 2024 UTC