develooper Front page | perl.php.sandwich.dev | Postings from August 2005

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

Thread Previous | Thread Next
From:
David Wheeler
Date:
August 2, 2005 11:18
Subject:
Re: Setting up a property on a Perl object causes segfault
Message ID:
F9403C98-2529-4C68-B6CE-1EB28D9FC54A@kineticode.com
On Aug 2, 2005, at 11:00 AM, João Pedro Gonçalves wrote:

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

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

So, you should *always* use accessor methods:

sub test {
     my $self = shift;
     return $self->{test} unless @_;
     $self->{test} = 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
Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About