|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: phpbugs at elygor dot de
New email:
PHP Version: OS:


 [2015-11-02 11:34 UTC] phpbugs at elygor dot de
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-23 23:35 UTC]
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]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-08-08 12:13 UTC]
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