when making a class in php what is the difference between these two :
class Search
function __construct()
{
$this->variable1= 1234;
}
}
and
class Search
private $variable1;
$variable1=1234;
function __construct()
{
}
}
if i need to access a value across different methods does it make any difference which approach i chose?
thank you
The difference between object and class variables is how you can access them.
$obj->varclass::$varYour class definition should be:
Versus:
Wether you use
varorpublicor theprivateaccess modifier is not what makes a variable an object property. The deciding factor is that it’s not declaredstatic, because that would make it accessible as class variable only.