Reputation: 31
I am getting this syntax error when running my php. Here is the code for a class I am trying to costruct:
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);
}
}
Anyone see whats wrong? Thanks!
Upvotes: 3
Views: 7105
Reputation: 41885
You need to set the visibility of $secret
private $secret = "";
Then just remove that casting on the base64 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);
}
}
Upvotes: 3
Reputation: 12039
I suggest you to declare $secret
as public
or private
& access it using $this->
. Example:
class mySimpleClass {
public $secret = "";
public function __construct($s) {
$this -> secret = $s;
}
public function getSecret() {
return base64_encode($this->$secret);
}
}
Upvotes: 0