Hay, when should variables be set within a PHP class?
<?php
class MyClass {
var $my_var; // here? like var $my_var = null;
function __construct(){
$this->my_var = null; // or here?
}
}
?>
Hay, when should variables be set within a PHP class?
<?php
class MyClass {
var $my_var; // here? like var $my_var = null;
function __construct(){
$this->my_var = null; // or here?
}
}
?>
It depends what you want to initialise them to. I prefer to initialise them when they're declared if possible, but if they need to be, for example, the result of a method call, then you'll need to initialise them in the constructor.