Setting up a property on a Perl object causes segfault
[email protected] (João Pedro Gonçalves) Tue, 2 Aug 2005 19:00:58 +0100
| Newsgroups | perl.php.sandwich.dev |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail-14-817054641
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Hi all,
please check the following script, based on t/16.t:
Changing in PHP a property on the perl object causes a segfault:
$obj->test = 2;
Where $obj was created in Perl.
Are properties read-only?
--Apple-Mail-14-817054641
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="objects.pl"
Content-Disposition: attachment;
filename=objects.pl
#!/usr/bin/perl -wl
use PHP::Interpreter;
use Data::Dumper;
my $p = PHP::Interpreter->new;
my $php = <<'EOPHP';
function print_object($obj)
{
echo "PERL ARRAY: " . $obj->parray[1] ."\n";
echo "PERL HASH: " . $obj->phash["foo"] ."\n";
}
function property_access($obj, $prop)
{
# $obj->add_in_php = 10;
return $obj->$prop;
}
function method_call($obj, $meth)
{
return $obj->$meth() * 10;
}
function props_as_array($obj)
{
$rv = array();
foreach($obj as $k => $v) {
$rv[$k] = $v;
}
return $rv;
}
function segfault_me($obj) {
echo $obj->test . "\n";
echo "Read OK .. writing to the propery segfaults:\n";
$obj->test = 2;
}
EOPHP
$p->eval($php);
my $foo = new Foo();
$foo->{bar} = 'apsomdmaposbar';
$foo->{baz} = 'baz';
print $p->get_class($foo);
print $p->property_access($foo, 'bar');
print $p->method_call($foo, 'get');
print "\n";
$p->print_object($foo);
print Dumper $p->props_as_array($foo);
$p->segfault_me($foo);
package Foo;
sub new {
my $self = shift;
my $class = ref($self) || $self;
bless {test => 1, parray => [1,2,3,4], phash => {foo => time}}, $class;
}
sub get {
my ($self) = @_;
return 10;
}
1;
--Apple-Mail-14-817054641
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=ISO-8859-1;
format=flowed
Jo=E3o Pedro Gon=E7alves
SAPO=
--Apple-Mail-14-817054641--