ehime
ehime

Reputation: 8375

Translating a Perl reference to OO PHP?

So I tripped across another oddity in translating the old developers Perl script into Object Orientated PHP, this little Perl reference statement has had me scratching my head for quite a while, but I haven't been able to figure it out via Google or friends.

I've tried my best to write out what I believe it to mean, but am uncertain if it is right. Could someone tell me if I figured it out or if I'm off? Thanks ahead of time.

The perl snippet is:

!$state->{$msg->{hash}}

I believe it means one of the two of these in OO PHP?

!$this->state[$this->msg['hash']] //or?
$this->state != $this->msg['hash']

Am I even in the ballpark?

UPDATE I was told this is a has reference, not an array reference, but I'm uncertain since $msg->{grey}, $msg->{hash}, $msg->{domain} etc all exist in the same sub?

Upvotes: 0

Views: 79

Answers (1)

user554546
user554546

Reputation:

Actually, on a second glance, $state is a hash reference of some kind (although it could also be a blessed object of some class), and $state->{$msg->{hash}} is the value of %$state corresponding to the key $msg->{hash} (which, in turn, is the value of %$msg that corresponds to the key "hash").

So, assuming that $state and $msg are only hash references (and not specific objects), they actually correspond to arrays in PHP (one of the really dumb things about PHP is that there is no difference between an array and an associative array).

So, it would be !$state[$msg['hash']] in PHP.

Upvotes: 1

Related Questions