|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53756 Unable to insert serialized objects with private variables in pgsql
Submitted: 2011-01-15 11:27 UTC Modified: 2011-05-31 11:52 UTC
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: admin at webdesignforall dot net Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.3.5 OS: Ubuntu 10.04 32 bit
Private report: No CVE-ID: None
 [2011-01-15 11:27 UTC] admin at webdesignforall dot net
Using php 5.3.5 with pdo_pgsql and pgsql 9.0.2 when inserting serialized objects 
that contain private variables the serialized string is truncate as soon as it 
hits the private variable.

Objects that do not contain private variables work fine.

When using the pdo_mysql driver it also works fine.

Test script:
class foo{
private $_var;
$foo=serialize(new foo());
$q=new PDO("pgsql:host=localhost;dbname=testdb","root","");
$q->exec('CREATE TABLE test (data TEXT)');
$s=$q->prepare("INSERT INTO test VALUES(?)");
$s=$q->query("SELECT * FROM test");

Expected result:
array(1) {
  array(1) {
    string(32) "O:3:"foo":1:{s:9:"foo_var";N;}"
string(32) "O:3:"foo":1:{s:9:"foo_var";N;}"

Actual result:
array(1) {
  array(1) {
    string(18) "O:3:"foo":1:{s:9:""
string(32) "O:3:"foo":1:{s:9:"foo_var";N;}"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-31 11:52 UTC]
-Status: Open +Status: Bogus
 [2011-05-31 11:52 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Serialized content of private/protected properties contain \0 inside the 
generated string. This causes truncation, to avoid it you need to change the 
column type to binary and write data as a binary string.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 19:01:29 2024 UTC