1

I'm trying to serialize a Doctrine_query object in Symfony :

var_dump(serialize($this->pager->getQuery()));

The result is :

string(2) "N;"

What am I doing wrong?

Tiois
  • 1,519
  • 1
  • 15
  • 32
  • Obvious question: What does `var_dump($this->pager->getQuery());` give? – Tomalak Nov 11 '10 at 16:12
  • The result of `$this->pager->getQuery()` is null... So that's what's being serialized... – ircmaxell Nov 11 '10 at 16:13
  • I tried "print_r($this->pager->getQuery())" and I get a big ouput beginning with "Doctrine_Query Object"... with many *RECURSION* – Tiois Nov 12 '10 at 13:20

1 Answers1

2

You can not serialize every object in PHP. Objects themselves - by implementing the Serializeable interface PHP Manual - can protect themselves from being serialized for example.

They return a NULL value then (or don't return anything which is then NULL in PHP). And that's exactly the contents of your serialized string: a serialized NULL (N;).

And there are even some build-in classes that go even further than that. But it applies as well to user-defined classes and build-in classes: Some of them are not available for serialization.


One example of a built-in class that can not be serialized in PHP is DOMDocument, however it is possible to add the functionality as the following question demonstrates:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836