Answer the question
In order to leave comments, you need to log in
Is it possible to change a class property?
Есть класс, который нельзя править
Class Test{
public q=5;
}
Answer the question
In order to leave comments, you need to log in
You should define this variable as static.
class Test
{
public static $p = 5;
public static print()
{
echo self::$p;
}
}
Test::$p = 9;
$obj = new Test();
$obj->print(); // 9
class Test
{
private static $_p = 5;
public $p;
public function __construct()
{
$this->p = self::$_p;
}
public function update($value)
{
$this->p = $value;
self::$_p = $value;
}
public static print()
{
echo $this->p;
}
}
$obj = new Test();
$obj->update(9);
$obj->print(); // 9
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question