Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization support #20

Merged
merged 5 commits into from
Sep 24, 2015
Merged

Conversation

mrferos
Copy link
Contributor

@mrferos mrferos commented Sep 22, 2015

Funky test because serializing an object with protected/private properties outputs zero-width binary characters. There are 1) hard to copy/paste and 2) result in the file being recognized as binary by GitHub resulting in no longer being able to do diffs easily. Below is an example:

<?php
require_once __DIR__ . '/vendor/autoload.php';

$map = new \Zumba\Swivel\Map(array(
    'feature.test' => array(1,2,3)
));



$d =  serialize($map);
echo $d, "\n";
echo md5($d), "\n";
$d = 'O:16:"Zumba\Swivel\Map":1:{s:6:"*map";a:1:{s:12:"feature.test";i:7;}}';
echo $d, "\n";
echo md5($d), "\n";

@mglinski
Copy link
Contributor

Implementing __set_state(array) here is still valid, it just does not cover the same cases as __sleep(). You were just trying to use __set_state() as __sleep(). The following code should work for the __set_state() use cases:

public static function __set_state($map_data) // As of PHP 5.1.0
{
    $map = new Map($map_data['map']);
    return $map;
}

@mrferos
Copy link
Contributor Author

mrferos commented Sep 24, 2015

@mglinski assuming $map_data['map'] contains unprocessed values that works, but var_export will echo out the already processed value of the map property. __set_state was created because of var_export and in a normal use case, it will produce an export calling __set_state on the logger. The logger interface does not implement __set_state so we can't guarantee this would work. The original implementation attempted to solve this by removing it but given the intended use case (#2), it looked like using __sleep/__wakeup more cleanly addressed it.

young-steveo added a commit that referenced this pull request Sep 24, 2015
@young-steveo young-steveo merged commit fa088c1 into zumba:master Sep 24, 2015
@mglinski
Copy link
Contributor

I will implement var_export() support in a new PR, should be up shortly.

Added in #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants