Bug #70835 [Opn]: array cast returns unusable index

From: Date: Wed, 23 Dec 2015 23:36:00 +0000
Subject: Bug #70835 [Opn]: array cast returns unusable index
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198187@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70835&edit=1 ID: 70835 Updated by: ajf@php.net Reported by: phpbugs at elygor dot de Summary: array cast returns unusable index Status: Open Type: Bug Package: Arrays related Operating System: Linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: It's even worse in PHP 7: get_object_vars() also produces an array with inaccessible indices. Previous Comments: ------------------------------------------------------------------------ [2015-11-02 11:34:36] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70835&edit=1

« previous php.bugs (#198187) next »