I was wondering if a class property is created and used in only one class method, if it is a class property at all, or should there be only a local variable accessible only for this class?
For example, whether to save a variable used in only one method as a local variable, such as:
class myClass { public function myMethod() { $_myVariableUsedOnlyOnce = "Hello World"; echo $_myVariableUsedOnlyOnce; } }
Or should I make the variable a private property of the class as follows:
class myClass { private $_myVariableUsedOnlyOnce; public function myMethod() { $this->_myVariableUsedOnlyOnce = "Hello World"; echo $this->_myVariableUsedOnlyOnce; } }
Which approach "smells"? What are the benefits of creating all the properties of a class of method variables other than when I need to print_r () the whole object for debugging purposes?
thanks
source share