I am trying to access a private member variable to use as a key in an array.
My class looks similar to this:
<?php
class MyClassName {
private $value;
private function MyFunction($array){
$some_html = "<b> $array[$this->value] <b>"; // error occurring on this line
return some_html;
}
}
?>
The error that I am getting is
PHP Parse error: syntax error, unexpected '-', expecting ']
If I store the private member variable before using it in the array there is no syntax error. This is interpreted fine:
<?php
class MyClassName {
private $value;
private function MyFunction($array){
$cache_key = $this->value;
$some_html = "<b> $array[$cache_key] <b>";
return $some_html;
}
}
?>
Is there something I am missing? I want to improve my understanding of what is happening here. Thanks.
MyFunctionreturns, actually, when you run it (in second case)?$valueto$cache_keybut not using it. My guess is that there is a syntax error somewhere in your real code.