php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61138 convert object
Submitted: 2012-02-19 05:57 UTC Modified: 2012-02-19 15:53 UTC
From: uginroot at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.10 OS: Windows 7
Private report: No CVE-ID: None
 [2012-02-19 05:57 UTC] uginroot at gmail dot com
Description:
------------
$product = json_decode('{"name":"Anton","1":"is not null"}');
print_r($product);
var_dump($product->name);
var_dump($product->{'1'});
$product = (array)$product;
print_r($product);
var_dump($product['name']);
var_dump($product['1']);

Test script:
---------------
<?php
$product = json_decode('{"name":"Anton","1":"is not null"}');
print_r($product);
var_dump($product->name);
var_dump($product->{'1'});
$product = (array)$product;
print_r($product);
var_dump($product['name']);
var_dump($product['1']);

Expected result:
----------------
stdClass Object
(
    [name] => Anton
    [1] => is not null
)
string(5) "Anton"
string(11) "is not null"
Array
(
    [name] => Anton
    [1] => is not null
)
string(5) "Anton"
string(11) "is not null"

Actual result:
--------------
stdClass Object
(
    [name] => Anton
    [1] => is not null
)
string(5) "Anton"
string(11) "is not null"
Array
(
    [name] => Anton
    [1] => is not null
)
string(5) "Anton"
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-19 06:19 UTC] aharvey@php.net
As documented at http://au2.php.net/manual/en/language.types.array.php, integer 
properties in objects that are cast to an array are inaccessible.
 [2012-02-19 06:19 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-02-19 15:53 UTC] uginroot at gmail dot com
Link is not working.
Why, then var_dump foreach and return the "right" keys and values​​? but the values ​​
in these keys are not available.

Ссылка не рабочая.
Почему тогда var_dump и foreach возвращают "правильные" ключи и значения? но 
значения по данным ключам недоступны.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC