Skip to content

Instantly share code, notes, and snippets.

@librasteve
Created August 4, 2022 20:55
Show Gist options
  • Save librasteve/afdfaae596038361e79579345e4f2c08 to your computer and use it in GitHub Desktop.
Save librasteve/afdfaae596038361e79579345e4f2c08 to your computer and use it in GitHub Desktop.
raku, Inline::Perl5 and PHP::Serialize
#phpsmake.php
1 #!/bin/env php
2 <?php
3
4 $array = [
5 "foo" => "bar",
6 "bar" => "foo",
7 ];
8
9 #print( var_dump($array) );
10
11 $as = serialize($array);
12 print( $as );
13
14 ?>
./phpsmake.php > dump.txt
#phptest.raku
1 use Inline::Perl5;
2 use PHP::Serialization:from<Perl5> <serialize unserialize>;
3
4 my $encoded = serialize({ a => 1, b => 2});
5 my $hashref = unserialize($encoded);
6 say $encoded;
7 say $hashref;
8
9 my $phpbuf = 'dump.txt'.IO.slurp;
10 say $phpbuf;
11 my $result = unserialize($phpbuf);
12
13 say $result;
raku phpstest.raku
a:2:{s:1:"a";i:1;s:1:"b";i:2;}
{a => 1, b => 2}
a:2:{s:3:"foo";s:3:"bar";s:3:"bar";s:3:"foo";}
{bar => foo, foo => bar}
@librasteve
Copy link
Author

make public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment