Re: Setting up a property on a Perl object causes segfault

[email protected] (David Wheeler) Tue, 2 Aug 2005 11:18:03 -0700
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
On Aug 2, 2005, at 11:00 AM, Jo=E3o Pedro Gon=E7alves wrote:

> Where $obj was created in Perl.
> Are properties read-only?

Properties in Perl cannot correspond to properties in PHP, since =20
there's no way to easily tell where they might be (a hash key? An =20
array index? Is the object a code reference that you would call like =20
C<$obj->(test =3D> 2)>?.

So, you should *always* use accessor methods:

sub test {
     my $self =3D shift;
     return $self->{test} unless @_;
     $self->{test} =3D shift;
}

Then, your PHP code should:

   echo $obj->test();
   echo $obj->test(2);

But I would certainly think that it shouldn't segfault, regardless.

Best,

David=