As I am learning PHP OOP and I see, there are lots of confusing parts. Here I have a single variable called public $file_link and I trying to assign default value as a superglobal variable. But I can't do like this, it gives a parse error. I am checking the whole file, again and again, to find what's the problem and I see that I cannot assign a default value as a variable in public property. so I need a setter method for public variable. (see my code comment for better understand). should I really need a method to set the value of public property??? (any better way of doing this).
class File_Link {
public $file_link = 'http://localhost' . $_SERVER["PHP_SELF"]; // CANNOT ASSIGN DEFAULT VALUE
const FILE_LINK = 'myRoot' . $_SERVER['PHP_SELF']; // CANNOT USE LIKE THIS
public $variable_name = "value";
public $variable_name_clone = $variable_name; // // I GET IT -> I CANNOT USE LIKE THIS BUT IT IS A PUBLIC VARIABLE
/*
For a public variable i need use a setter method????? // FOR A SINGLE LINE I HAVE TO USE THE BELOW CODE WHAT THE >>>>>
*/
public $host_link = 'http://localhost'; // THIS WORKS PERFECTLY
public setFileLink() {
$this->file_link . $_SERVER["PHP_SELF"];
}
}