Unexpected T_VARIABLE pending T_FUNCTION fix
I am getting this syntax error when I run my php. Here is the code for the class I am trying to calculate:
function makeObject($s) {
$secobj = new mySimpleClass($s);
return $secobj;
}
class mySimpleClass {
$secret = "";
public function __construct($s) {
$this -> secret = $s;
}
public function getSecret() {
return base64_encode(string $secret);
}
}
Does anyone see what happened? Thank!
+3
source to share
2 answers
You need to set visibility $secret
private $secret = "";
Then just remove that base64 casting and use $this->secret
to access the property:
return base64_encode($this->secret);
So finally:
class mySimpleClass
{
// public $secret = "";
private $secret = '';
public function __construct($s)
{
$this->secret = $s;
}
public function getSecret()
{
return base64_encode($this->secret);
}
}
+3
source to share