Конечно, сам метод может назначать явные значения свойствам.
public function reset()
{
$this->someString = "original";
$this->someInteger = 0;
}
$ this-> SetInitialState () из Конструктора
Так же, как и другая идея, у вас может быть метод, который сам устанавливает значения по умолчанию и вызывается из конструктора. Вы можете позвонить и в любой момент позже.
<?php
class MyClass {
private $var;
function __construct() { $this->setInitialState(); }
function setInitialState() { $this->var = "Hello World"; }
function changeVar($val) { $this->var = $val; }
function showVar() { print $this->var; }
}
$myObj = new MyClass();
$myObj->showVar(); // Show default value
$myObj->changeVar("New Value"); // Changes value
$myObj->showVar(); // Shows new value
$myObj->setInitialState(); // Restores default value
$myObj->showVar(); // Shows restored value
?>