什么是“->”? PHP 运算符叫什么?

发布于 2024-09-27 15:58:04 字数 106 浏览 1 评论 0原文

PHP 中的这个箭头 -> 运算符怎么称呼?

它可以是减号、破折号或连字符,后跟大于号(或右 V 形符号)。

大声朗读代码时如何发音?

What do you call this arrow looking -> operator found in PHP?

It's either a minus sign, dash or hyphen followed by a greater than sign (or right chevron).

How do you pronounce it when reading code out loud?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(15

白日梦 2024-10-04 15:58:04

正式名称是“对象运算符” - T_OBJECT_OPERATOR

The official name is "object operator" - T_OBJECT_OPERATOR.

失去的东西太少 2024-10-04 15:58:04

我称之为“飞镖”;如 $Foo->bar() :“Foo dart bar”

由于许多语言都使用“点”,如 Foo.bar(); 我想要一个 -要使用的音节词。 《箭》实在是太啰嗦了! ;)

由于 PHP 使用 . “dot” 进行连接(为什么?)我不能安全地说“dot”——它可能会造成混淆。

不久前与一位同事讨论时,我们决定将“dart”作为一个与“点”足够相似的词,以便流畅地表达,但又足够独特(至少当我们这么说时),不会被误认为是连接的“点” 。

I call it "dart"; as in $Foo->bar() : "Foo dart bar"

Since many languages use "dot" as in Foo.bar(); I wanted a one-syllable word to use. "Arrow" is just too long-winded! ;)

Since PHP uses . "dot" for concatenation (why?) I can't safely say "dot" -- it could confuse.

Discussing with a co-worker a while back, we decided on "dart" as a word similar enough to "dot" to flow comfortably, but distinct enough (at least when we say it) to not be mistaken for a concatenating "dot".

∞梦里开花 2024-10-04 15:58:04

当大声阅读 PHP 代码时,我不发音“->”操作员。对于 $db->prepare($query); 我主要说“Db [短暂停顿]准备查询。”所以我想我说它就像普通句子中的逗号一样。

Paamayim Nekudotayim(“::”)也是如此。

When reading PHP code aloud, I don't pronounce the "->" operator. For $db->prepare($query); I mostly say "Db [short pause] prepare query." So I guess I speak it like a comma in a regular sentence.

The same goes for the Paamayim Nekudotayim ("::").

ˇ宁静的妩媚 2024-10-04 15:58:04

当我自己阅读代码时,我认为它就像一个“占有欲的东西”。

例如:

x->value = y->value

将读取“x 的值等于 y 的值”

When reading the code to myself, I think of it like a "possessive thing".

For example:

x->value = y->value

would read "x's value equals y's value"

傲影 2024-10-04 15:58:04

大多数情况下,我使用 @Tor Valamo 方法的一些变体(“A 的 B 方法”或“A 的 B 方法”),但有时我会说“点”。例如“调用 A 点 B()”。

Most often, I use some variation on @Tor Valamo's method ("the B method of A" or "A's B method"), but I sometimes say "dot". E.g. "call A dot B()".

情深已缘浅 2024-10-04 15:58:04

物业经营者。

当大声阅读 $a->b()$a->b 时,我只是说“在 $a 对象上调用 b”或“从/获取 b”美元/美元”

Property operator.

When reading $a->b() or $a->b loud I just say "call b on the $a obj" or "get b from/in/of $a"

彩虹直至黑白 2024-10-04 15:58:04

我个人喜欢详细地口头表达我的代码。

例如:

$foo = new Foo();
echo $foo->bar

读作如下:

echo(/print) 对象 foo 的 bar 属性。

它很冗长而且更耗时,但我发现如果有理由让我口头表达我的代码,那么我可能需要清楚我到底在传达什么。

I personally like to be verbose in expressing my code verbally.

e.g.:

$foo = new Foo();
echo $foo->bar

would read as such:

echo(/print) the bar property of object foo.

It's verbose and more time consuming, but I find if there is a reason for me to be expressing my code verbally, then I probably need to be clear as to what I'm communicating exactly.

弥繁 2024-10-04 15:58:04

回到 Cobol 'in',你会说“将 5 移到 a 中的 b”。今天大多数语言都从另一个方向限定事物。

但我仍然会将 $a->b(); 读作“在 a 中调用 b”。

Harkening back to the Cobol 'in' where you would say "Move 5 to b in a." Most languages today qualify things the other direction.

Yet I would still read $a->b(); as "Call b in a".

寄离 2024-10-04 15:58:04
$a->b 

我称之为“$a 的参数 b”。

$a->b()

我称之为“$a 的函数 b”。

$a->b 

I call as "param b of $a".

$a->b()

I call as "function b of $a".

别在捏我脸啦 2024-10-04 15:58:04

单箭头可以轻松地口头称为 PHP OOP 的含义:成员。因此,对于 $a->var 你会说“Object a's member var”。

大声阅读代码时,它确实有助于提前阅读(先行参考,抱歉),并了解您实际上可能指的是什么。例如,让我们有以下代码:

<?php
  Class MyClass {
    $foo = 0;

    public function bar() {
      return $this->foo;
    }
  }

  $myobject = new MyClass();
  $myobject->bar();
?>

因此,如果我要大声朗读此代码块作为代码演示,我会这样说:

"定义类'MyClass',开大括号。变量'foo'等于0,终止行。定义公共函数'bar'开闭括号,开大括号。返回对象'this'的成员变量'foo' ,终止行。将“MyClass”的新实例(无参数)实例化为变量对象“myobject”,终止行。”< /p>

但是,如果我大声朗读代码供其他学生或程序员在没有视觉效果的情况下进行复制,那么我会说:

"PHP 开放标记(完整)、换行符、缩进、Class MyClass 开括号、换行符。缩进、['dollar-sign' | 'Object-marker'] foo 等于 0、分号、换行符、换行符。公共函数bar 开闭括号、开括号、换行符、返回 ['dollar-sign' | 'Object-marker'] this 箭头 foo、分号、换行符。闭括号、换行符、换行符。 ['dollar-sign' | 'Object-marker'] myobject 等于 new MyClass 开闭括号、分号、换行符。开闭括号、分号、换行符、PHP 结束标记。”

你在哪里看到 ['dollar-sign' | '对象标记'],只需选择您倾向于代表'$'的那个,我经常在两者之间切换,这取决于我的听众。

所以,总结一下,在 PHP 中,->指对象的成员,可以是变量、另一个对象或方法。

The single arrow can easily be referred verbally as what it means for PHP OOP: Member. So, for $a->var you would say "Object a's member var".

When reading code aloud, it does help to read ahead (lookahead reference, sorry), and know what you may actually be referring to. For instance, let's have the following bit of code:

<?php
  Class MyClass {
    $foo = 0;

    public function bar() {
      return $this->foo;
    }
  }

  $myobject = new MyClass();
  $myobject->bar();
?>

So, if I were to read aloud this code block as a demonstration of code, I would say this:

"Define Class 'MyClass', open-brace. Variable 'foo' equals zero, terminate line. Define public function 'bar' open-close parentheses, open-brace. Return member variable 'foo' of object 'this', terminate line. Close-brace, close-brace. Instantiate new instance of 'MyClass' (no arguments) as variable object 'myobject', terminate line. Call member method 'bar' of object 'myobject', terminate line."

However, if I were reading the code aloud for other students or programmers to copy without a visual, then I would say:

"PHP open tag (full), newline, indent, Class MyClass open-brace, newline. Indent, ['dollar-sign' | 'Object-marker'] foo equals 0, semicolon, newline, newline. public function bar open-close parentheses, open-brace, newline. Indent, return ['dollar-sign' | 'Object-marker'] this arrow foo, semicolon, newline. Reverse-indent, close-brace, newline, reverse-indent, close-brace, newline, newline. ['dollar-sign' | 'Object-marker'] myobject equals new MyClass open-close parentheses, semicolon, newline. ['dollar-sign' | 'Object-marker'] myobject arrow bar open-close parentheses, semicolon, newline. Reverse-indent, PHP close tag."

Where you see ['dollar-sign' | 'Object-marker'], just choose whichever you tend to speak for '$', I switch between the two frequently, just depends on my audience.

So, to sum it up, in PHP, -> refers to a member of an object, be it either a variable, another object, or a method.

不寐倦长更 2024-10-04 15:58:04

我工作的高级 PHP 开发人员说“箭头”。

$A->B;

当他让我输入上述内容时,他会说“Dollar A arrow B”或

$A->B();

“Dollar A arrow B parens”。

The senior PHP developer where I work says "arrow".

$A->B;

When he's telling me to type the above, he'll say, "Dollar A arrow B" or for

$A->B();

"Dollar A arrow B parens."

一萌ing 2024-10-04 15:58:04

我会这样做:

//Instantiated object variable with the name mono call property name
$mono->name;

//Instantiated object variable with the name mono call method ship
$mono->ship();

在我的书中( PHP Master,作者:Lorna Mitchell),它被称为对象运算符

I would do it like this:

//Instantiated object variable with the name mono call property name
$mono->name;

//Instantiated object variable with the name mono call method ship
$mono->ship();

In my book (PHP Master by Lorna Mitchell) it's called the object operator.

苏别ゝ 2024-10-04 15:58:04

user187291已经回答了非主观问题,至于主观问题,我说“sub”。例如,我会将 $x->y 发音为“x sub y” - 在这种情况下,“sub”是“下标”的缩写。这更适合数组表示法; $x['y'] 我也发音“x sub y”。通常,当大声朗读代码时,我会用我的话来识别其他开发人员可以看到的行,因此歧义尚未成为问题。我相信原因是我将结构/对象和数组视为“集合”,并且其元素按照数学符号中的下标表示。

user187291 has answered the non-subjective question, as for the subjective one, I say "sub". For example, I would pronounce $x->y as "x sub y" - "sub" in this context is short for "subscript". This is more appropriate for array notation; $x['y'] I also pronounce "x sub y". Typically when reading code out loud, I am using my words to identify a line the other developer can see, so the ambiguity has yet to become a problem. I believe the cause is that I view structs/objects and arrays as "collections", and elements thereof are subscripted as in mathematical notation.

爱本泡沫多脆弱 2024-10-04 15:58:04

日语有一个方便的助词,“no”(の)。它是所有格助词,大致意思是“与前一个术语相关”。

“弗雷德の獾”的意思是“弗雷德的獾”。

这是一个很长的说法,至少在心理上,而且在那些懂日语的人中,我倾向于通过将它们读作来区分它们:

$A->B(); // "Call $A's B."
C::D();  // "Call C の D."

但是对于非日语使用者来说,将两者读作所有格“'s”也可以。你也可以翻转它们并使用“of”,所以“D of C”......但这有点尴尬,而且很难做到你正在快速阅读,因为它破坏了你的线性流程。

不过,如果我进行口述,也许在配对编码并建议输入什么内容时,我会将特定字符称为“破折号大于箭头”和“双冒号”(如果我认识我正在说话的人) to 是一名 PHPophile,我第一次可能会称其为“paamayim nekudotayim 双冒号”,部分是因为这是一个很酷的笑话,部分是为了防止他们“纠正”我)。

Japanese has a convenient particle for this, "no" (の). It is the possessive particle, meaning roughly "relating to the preceding term".

"Fred の badger" means "Fred's badger".

Which is a long way round of saying that at least mentally, and also amongst those who understand Japanese, I tend to differentiate them by reading them as:

$A->B(); // "Call $A's B."
C::D();  // "Call C の D."

But reading both as a possessive "'s" works too, for non-Japanese speakers. You can also flip them and use "of", so "D of C"... but that's kinda awkward, and hard to do it you're reading rapidly because it breaks your linear flow.

If I were dictating, though, perhaps when pair coding and suggesting what to type, I'd refer to the specific characters as "dash-greater-than arrow" and "double-colon" (if i know the person I'm talking to is a PHPophile, I might call that a "paamayim nekudotayim double-colon" the first time, partly because it's a cool in-joke, partly to prevent them from "correcting" me).

゛时过境迁 2024-10-04 15:58:04

目的。所以 $a->$b->$c 将是“A 对象 B 对象 c”。

Object. So $a->$b->$c would be 'A object B object c'.

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