将 Perl 引用转换为 OO PHP?

发布于 2024-12-19 06:09:16 字数 521 浏览 0 评论 0原文

因此,我在将旧开发者 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

司马昭之心 2024-12-26 06:09:16

实际上,仔细一看,$state 是某种哈希引用(尽管它也可能是某个类的 blessed 对象),而 $ 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文