In some contexts, we can use an array($this, 'variable') syntax, to refer to object properties. Why doesn’t compact(array($this, 'variable')) work? Is there a way to work around this?
class someclass {
$result = 'something';
public function output() {
compact($this->result); // $this is a OOP keyword and I don't know how to use it inside a compact() brackets
}
}
I have found only one solution at the moment:
$result = $this->result;
compact('result');
But this is ugly.
Short answer: don’t use
compact(). In this situation, it’s pointless (in most situations it’s pointless, but that’s another story). Instead, what’s wrong with just returning an array?