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

Support for circular references is missing #12

Open
denisvmedia opened this issue Feb 1, 2019 · 1 comment
Open

Support for circular references is missing #12

denisvmedia opened this issue Feb 1, 2019 · 1 comment

Comments

@denisvmedia
Copy link

denisvmedia commented Feb 1, 2019

This code fails:

package main

import (
	"github.com/elliotchance/phpserialize"
	"fmt"
)

type A struct {
	Id string
	B *B
}
type B struct {
	Id string
	A *A
}

func main() {
	var in A
	err := phpserialize.Unmarshal(
		[]byte(`O:1:"A":2:{s:2:"id";s:1:"1";s:1:"b";O:1:"B":2:{s:2:"id";s:1:"2";s:1:"a";r:1;}}`),
		&in1,
	)
	fmt.Println(err)
	fmt.Println(in)
}

The error I'm getting: can not consume type: r:1;}}
The serialized string I used comes from PHP. Vice versa it doesn't work as well - crashes because of endless recursion.

P.S. PHP code I used:

<?php

class A {
    public $id;
    public $b;
}

class B {
    public $id;
    public $a;
}

$a = new A();
$b = new B();
$a->id = "1";
$a->b = $b;
$b->a = $a;
$b->id = "2";

var_dump(serialize($a));
var_dump(serialize($b));
?>
@elliotchance
Copy link
Owner

Thanks for reporting this. I won't have to time to fix this, but always welcome pull requests.

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

No branches or pull requests

2 participants