# Serialization question

- Thread: https://externals.io/message/15504
- Original archive: https://news-web.php.net/php.internals/15504
- Started by l0t3k on 2005-03-20T16:29:57+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15504 — l0t3k — 2005-03-20T16:29:57+00:00

URL: https://externals.io/message/15504#15504

a quick question about the new serialization callbacks. is it necessary only
to serialize the state specific to the given object, or

do we also have to explicitly serialize the properties hash ?

Assuming my classes are set up as below, will the serialization mechanism
take care of subclasses for me
(calling __sleep etc). if not what more do i need to accomodate userland
subclasses ?


typedef struct php_locale_object {
  zend_object std;
  void *ptr;
} php_locale_object;


/* {{{ Locale serialization support **/

static int locale_serialize(zval *object, unsigned char **buffer, zend_uint
*buf_len, zend_serialize_data *data TSRMLS_DC)
{
 Locale *loc = I18N_FETCH_OBJ(object, Locale *);
 char *name, *result;
 int len;

 name = (char *)loc->getName();
 len = strlen(name);
 result = (len > 0) ? estrndup(name, len) : NULL;
 *buffer = (unsigned char*)result;
 *buf_len = (zend_uint)len;

 return SUCCESS;
}



static int locale_unserialize(zval **object, zend_class_entry *ce, const
unsigned char *buf,
   zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC)
{
 Locale *loc;

 if (buf_len) {
  Locale temp = Locale::createFromName((char *)buf);

  loc = new Locale(temp);
 } else {
  loc = new Locale();
 }

 *object = php_locale_new(loc TSRMLS_CC);

 return SUCCESS;
}

/* }}} */


l0t3k

---

## #15511 — Marcus Boerger — 2005-03-20T19:34:41+00:00

URL: https://externals.io/message/15504#15511 · In reply to: #15504

Hello l0t3k,

Sunday, March 20, 2005, 5:29:57 PM, you wrote:


> a quick question about the new serialization callbacks. is it necessary only
> to serialize the state specific to the given object, or

> do we also have to explicitly serialize the properties hash ?

You have to do all your own (.) answers all further question

(snip)

marcus

---

## #15513 — Marcus Boerger — 2005-03-20T20:18:42+00:00

URL: https://externals.io/message/15504#15513 · In reply to: #15512

Hello l0t3k,

Monday, March 21, 2005, 12:14:03 PM, you wrote:

> Marcus,
>   i just read through var.c (specifically php_var_serialize_intern) and it
> seems as if the properties hash is handled correctly if the user specifies
> __sleep and __wakeup.

> IOW, the custom callback is called, then _sleep is called to determine how
> to further handle properties.

Thanks for checking that, i didn't new and imho it is absolutley wrong.
Instead the user should call that funcs his own in an overloaded class
of the c code should enforce calling it otherwise. I think so becuase
the whole idea of being able to overload serializing at c level is that
there might be classes that do not have standard properties implemented
and hence a call to __sleep/__wakeup does not make sense.

regards
marcus


> "Marcus Boerger" <mail@marcus-boerger.de> wrote in message 
> news:1245669636.20050320203441@marcus-boerger.de...

> > […]




-- 
Best regards,
 Marcus                            mailto:mail@marcus-boerger.de

---

## #15512 — l0t3k — 2005-03-21T11:14:03+00:00

URL: https://externals.io/message/15504#15512 · In reply to: #15511

Marcus,
  i just read through var.c (specifically php_var_serialize_intern) and it 
seems as if the properties hash is handled correctly if the user specifies 
__sleep and __wakeup.

IOW, the custom callback is called, then _sleep is called to determine how 
to further handle properties.

l0t3k



"Marcus Boerger" <mail@marcus-boerger.de> wrote in message 
news:1245669636.20050320203441@marcus-boerger.de...

> You have to do all your own (.) answers all further question
>
> (snip)
>
> marcus
