I found out that this work:
$var = 'value';
$obj = new myClass();
class myClass{
function __construct(){
$this->myFunc($var);
}
public function myFunc($var){
echo $var;
}
}
But is it a good pratice ? Or i should just do it like this?
$var = 'value';
$obj = new myClass($var);
class myClass{
public $var;
function __construct($var){
$this->var = $var;
$this->myFunc($this->var);
}
public function myFunc($var){
echo $var;
}
}
Or,if both can be used , when it's recommended to use one and when, the other? Also , is there a good website,blog,topic,tutorial about best practices for php including oop ?
EDIT: Seems like using variables does not output the value,but does not give an error neither.My initial code use constants and i thought it would also work with variables:
define('blabla','value');
$obj = new myClass();
class myClass{
function __construct(){
$this->myFunc(blabla);
}
public function myFunc($var){
echo $var;
}
}