Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

今天还在和同事讨论getter需不需要加get #1

Open
Veitor opened this issue Dec 4, 2018 · 1 comment
Open

今天还在和同事讨论getter需不需要加get #1

Veitor opened this issue Dec 4, 2018 · 1 comment

Comments

@Veitor
Copy link

Veitor commented Dec 4, 2018

PSR规范中貌似没有提到这一点

class Foo
{
    private $bar;

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

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

对于这样的类,似乎也没有强制性规定如何获取私有属性,获取属性的方法名要不要带get

同事调侃是时候区分.Net和Java程序员了

@iwind
Copy link
Owner

iwind commented Dec 17, 2018

抱歉,现在才看到。PSR是比较“正规”的标准,所以不会省略get,我在这里列举的是我在别的语言中常用的一些经验,无论这些细节是什么,指导思想不是“正规”,而是让程序员写起来更加自然、简洁。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants