php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30417 serialize private
Submitted: 2004-10-13 03:28 UTC Modified: 2004-10-13 16:35 UTC
From: pickwd at videotron dot ca Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.2 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
48 - 7 = ?
Subscribe to this entry?

 
 [2004-10-13 03:28 UTC] pickwd at videotron dot ca
Description:
------------
Some on can explain me that: 

<? 
class B { 
public $v; 
} 

class A { 
private $v; 
} 

$a= new A(); 
$b= new B(); 

$sa1= 'O:1:"A":1:{s:4:"Av";N;}';//Text of serialized A 
$sb1= 'O:1:"B":1:{s:1:"v";N;}';//Text of serialized B 

$a1= unserialize($sa1); 
$b1= unserialize($sb1); 

print_r($a1);//Weird 
print_r($b1);//ok B Object ( [v] => ) 

$sa= serialize($a); 
$sb= serialize($b); 

$a= unserialize($sa); 
$b= unserialize($sb); 
print_r($a);//ok A Object ( [v:private] => ) 
print_r($b);//ok B Object ( [v] => ) 
?> 

If I serialise object with private member I'm unable unserialise it! 



Reproduce code:
---------------
<? 
class B { 
public $v; 
} 

class A { 
private $v; 
} 

$a= new A(); 
$b= new B(); 

$sa1= 'O:1:"A":1:{s:4:"Av";N;}';//Text of serialized A 
$sb1= 'O:1:"B":1:{s:1:"v";N;}';//Text of serialized B 

$a1= unserialize($sa1); 
$b1= unserialize($sb1); 

print_r($a1);//Weird 
print_r($b1);//ok B Object ( [v] => ) 

$sa= serialize($a); 
$sb= serialize($b); 

$a= unserialize($sa); 
$b= unserialize($sb); 
print_r($a);//ok A Object ( [v:private] => ) 
print_r($b);//ok B Object ( [v] => ) 
?> 


Expected result:
----------------
The print of the A unserialize

Actual result:
--------------
nothing

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-13 11:28 UTC] helly@php.net
You did not copy the serialized data correctly. It contains NUL chars!

The following shows it:
'O:1:"A":1:{s:4:"Av";N;}'
..............^ length of property name

It says length is 4 but you only gave 2 chars.
 [2004-10-13 16:35 UTC] pickwd at videotron dot ca
I know for the lenght it's the weird problem, it's the goof result of the serialize and not an error of copy/paste
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC