Is there a general rule of thumb, when we should pass a value as as class variable and when as a method argument? Or is it just a choice of the developer?
For example -- are there any reasons, why following (PHP code):
class SomeClass
{
public function __construct()
{
$this->id = $_GET['id'];
$this->showMessage();
}
public function showMessage()
{
echo 'The ID is '.$this->id;
}
}
is better (or worse?) than this:
class SomeClass
{
public function __construct()
{
$this->showMessage($_GET['id']);
}
public function showMessage($id)
{
echo 'The ID is '.$id;
}
}
Note, that I'm only asking about differences between passing value as class variable vs. passing as method argument. Please, don't point out, that I should never operate directly on superglobals in PHP. I know, that this is wrong. I used it here, to simplify the example.