php.net |  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
Votes:4
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: admin at webdesignforall dot net
New email:
PHP Version: OS:

 

 [2011-01-15 11:27 UTC] admin at webdesignforall dot net
Description:
------------
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:
---------------
<?php
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->bindValue(1,$foo);
$s->execute();
$s=$q->query("SELECT * FROM test");
var_dump($s->fetchAll(PDO::FETCH_ASSOC),$foo);

Expected result:
----------------
array(1) {
  [0]=>
  array(1) {
    ["data"]=>
    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) {
  [0]=>
  array(1) {
    ["data"]=>
    string(18) "O:3:"foo":1:{s:9:""
  }
}
string(32) "O:3:"foo":1:{s:9:"foo_var";N;}"


Patches

Pull Requests

History

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

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: Thu Oct 31 22:01:27 2024 UTC