class A{
public $name;
public function __construct() {
$this->name = 'first';
}
public function test1(){
if(!empty($_POST["name"]))
{
$name = 'second';
}
echo $name;
}
$f = new A;
$f->test1();
Why don't we get first and how set right default value variable $name only for class A?
I would be grateful for any help.
$this->nameand$nameare two different variables...$nameisfirst? if makepublic $name; $this->name='first';it not will be printfirst.$this->nameinstead of$nameinside yourtest1()function. The other part was fine as it was, you can revert that to your initial version.