将 Perl 引用转换为 OO PHP?
因此,我在将旧开发者 Perl 脚本翻译为 面向对象的 PHP,这个小小的 Perl 参考语句让我摸不着头脑 头了很长一段时间,但我一直无法通过谷歌或朋友弄清楚。
我已尽力写出我认为的意思,但不确定它是否是 正确的。有人可以告诉我我是否已经弄清楚或者我是否已经离开了吗?提前致谢。
Perl 片段是:
!$state->{$msg->{hash}}
我相信这意味着 OO PHP 中的这两个之一?
!$this->state[$this->msg['hash']] //or?
$this->state != $this->msg['hash']
我还在球场上吗?
更新 有人告诉我这是一个 has 引用,而不是数组引用,但我不确定,因为 $msg->{grey}、$msg->{hash}、$msg-> ;{domain} 等都存在于同一个子目录中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,仔细一看,
$state
是某种哈希引用(尽管它也可能是某个类的bless
ed 对象),而$ state->{$msg->{hash}}
是$msg->{hash}
键对应的%$state
的值> (反过来,它的值是对应于键“hash”
的%$msg
)。因此,假设
$state
和$msg
只是哈希引用(而不是特定对象),它们实际上对应于 PHP 中的数组(PHP 中真正愚蠢的事情之一)是数组和关联数组之间没有区别)。因此,在 PHP 中它将是
!$state[$msg['hash']]
。Actually, on a second glance,
$state
is a hash reference of some kind (although it could also be abless
ed 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.