PHP类实例化。要使用还是不使用括号? [英] PHP class instantiation. To use or not to use the parentheses?
问题描述
我一直假设 - 在没有构造函数参数的情况下,在创建类实例时,括号(大括号)跟随类名称,是可选的,并且您可以根据自己的个人喜好包含或排除它们。
I've always assumed that - in the absence of constructor parameters - the parentheses (curly brackets) follow the class name when creating a class instance, were optional, and that you could include or exclude them at your own personal whim.
这两个语句是相等的:
$foo = new bar;
$foo = new bar();
我是对吗?
我知道这听起来像一个RTFM问题,但我一直在寻找一段时间(包括整个PHP OOP部分),我似乎找不到一个直接的答案。
I know this sounds like a RTFM question, but I've been searching for a while (including the entire PHP OOP section) and I can't seem to find a straight answer.
推荐答案
如果您不是通过任何代码约定编写代码,请使用您更喜欢的代码。就我个人而言,我喜欢离开它,因为它真的只是杂乱的给我。
They are equivalent. If you are not coding by any code convention, use which you like better. Personally, I like to leave it out, as it is really just clutter to me.
这篇关于PHP类实例化。要使用还是不使用括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!