What is the difference between $this->id and $id.
class Test{
public $id;
function Test(){
$this->id = 1;
}
}
===
class Test{
public $id;
function test(){
$id = 1;
}
}
how to get the variable from other class?
class TestA{
public $test;
function TestA(){
$this->test = new Test();
echo $this->test->id;
}
}
phpdoesn’t work in a wayC++,JavaandC#work.In php you should always use
$thisreference and->operator to access the instance variables.So the first code assigns
1to the instanceidproperty, and in the second you’re assigning1to a local$idvariable.