是否有任何命名约定来执行 php 按引用传递或按值传递?
我可以写一个像这样的函数:
public function removeRubbishTag(&$aString)
另外,我可以有一个像这样的函数:
public function removeRubbishTag($aString)
但是当你仔细查看参数时,很容易让其他人感到困惑。 PHP 社区是否有一些命名约定来让人们轻松判断变量是 passByReference 还是 value?谢谢。
I can write a function like :
public function removeRubbishTag(&$aString)
Also, I can have a function like this:
public function removeRubbishTag($aString)
But when you look at the params carefully, it is easy to confuse others. Do the PHP community have some naming convention to let people tell easily if a variable is passByReference or value? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,这些领域的一致性并不是 PHP 的强项。但一般来说,你的问题的答案是:“不,没有标准约定”。
旁注:
事情变得更加复杂,因为传递引用与传递引用并不完全相同:
输出:
虽然这个:
输出:
而这个:
输出:
和
输出:
Unfortunately, consistency in these areas is not a PHP strong suit. But generally the answer to your question is, "no, there is no standard convention".
Side note:
Things are made more complicated by the fact that pass-by-reference is not quite the same thing as pass-a-reference:
Outputs:
While this:
Outputs:
And this:
Outputs:
And
Outputs:
我还没有看到 PHP 中发送到函数的变量的命名标准。至于PHP的编码标准,可以参考PEAR编码标准。 http://pear.php.net/manual/en/standards.php
但没有提及变量命名约定。
I haven't seen a naming standard for variables being sent into functions in PHP. As for coding standards for PHP, you can reference the PEAR coding standards. http://pear.php.net/manual/en/standards.php
There's no mention of variable naming conventions for this though.
没有命名约定。特别是 b/c 有时,与对象一样,引用的传递是隐式的。
There is no naming-convention. Especially b/c sometimes, as with objects, the pass by ref is implicit.