开发者

Store function result or call it each time? [closed]

开发者 https://www.devze.com 2023-03-13 10:42 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a class with a protected variable in it which can be get by a function getVariable().

How much difference will it make if i'll call getVariable() every time instead of storing the result once and then use it? (the getVariable(开发者_如何学编程) does nothing more than return $this->var)


It should not matter either way for you, premature optimization is bad. Do what makes sense design wise, not optimization wise. Either way, function/method calls in php are pretty cheap.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号