php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61110 The same codes output the different results between ver5.3.8 & ver5.3.10
Submitted: 2012-02-16 17:58 UTC Modified: 2012-02-17 02:08 UTC
From: tansuanna at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.10 OS: CentOS 5.5
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: tansuanna at gmail dot com
New email:
PHP Version: OS:

 

 [2012-02-16 17:58 UTC] tansuanna at gmail dot com
Description:
------------
The same codes output the different results between ver5.3.8 & ver5.3.10:
<?php
$a = serialize((object)array(
’1′ => ‘aaa’,
’2′ => ‘bbb’,
’3′ => ‘ccc’,
));
$a = (array)unserialize($a);
$a[1] = ‘ddd’;
var_dump($a);
?>

// results before ver5.3.8:
array(3) {
[1]=>
string(3) “ddd”
[2]=>
string(3) “bbb”
[3]=>
string(3) “ccc”
}

// results in ver5.3.10:
array(4) {
["1"]=>
string(3) “aaa”
["2"]=>
string(3) “bbb”
["3"]=>
string(3) “ccc”
[1]=>
string(3) “ddd”
}

Test script:
---------------
<?php
$a = serialize((object)array(
’1′ => ‘aaa’,
’2′ => ‘bbb’,
’3′ => ‘ccc’,
));
$a = (array)unserialize($a);
$a[1] = ‘ddd’;
var_dump($a);
?>

Expected result:
----------------
output same results in their versions:
array(3) {
[1]=>
string(3) “ddd”
[2]=>
string(3) “bbb”
[3]=>
string(3) “ccc”
}

Actual result:
--------------
// results before ver5.3.8:
array(3) {
[1]=>
string(3) “ddd”
[2]=>
string(3) “bbb”
[3]=>
string(3) “ccc”
}

// results in ver5.3.10:
array(4) {
["1"]=>
string(3) “aaa”
["2"]=>
string(3) “bbb”
["3"]=>
string(3) “ccc”
[1]=>
string(3) “ddd”
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-17 00:53 UTC] aharvey@php.net
This came about as a result of the fix for bug #55798 in 5.3.9. At some point, 
we've just got to pick a behaviour and stick with it: the new behaviour at least 
makes the unserialised properties accessible, which is better than the old.
 [2012-02-17 00:53 UTC] aharvey@php.net
-Status: Open +Status: Not a bug -Package: Output Control +Package: Class/Object related
 [2012-02-17 01:54 UTC] tansuanna at gmail dot com
but i cant get the values:
var_dump(isset($a[2])); // false
var_dump(isset($a['2'])); // false

$id = strval(2);
var_dump(isset($a[$id])); // false
 [2012-02-17 02:01 UTC] tansuanna at gmail dot com
how to get the value of $a[2]?
var_dump($a['2']); //NULL
 [2012-02-17 02:08 UTC] aharvey@php.net
Yes, because you're explicitly casting to an array: as the "Converting to Array" 
section of the manual says, integer properties are inaccessible at that point.
 [2012-02-17 02:22 UTC] tansuanna at gmail dot com
i got it.thank you.but i had to check my all codes and make sure i can update my 
php version safely.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 04 11:01:30 2025 UTC