| Summary: | Accessing $this as an array marks the code as syntax error, even though it is a correct syntax in PHP | ||
|---|---|---|---|
| Product: | [Applications] kdevelop | Reporter: | Jan Pavlicek <jan.pavlicek> |
| Component: | Language Support: PHP | Assignee: | kdevelop-bugs-null |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | normal | CC: | alexander |
| Priority: | NOR | ||
| Version First Reported In: | 5.0.3 | ||
| Target Milestone: | --- | ||
| Platform: | Arch Linux | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
*** This bug has been marked as a duplicate of bug 346876 *** |
Using this construction, which is perfectly valid in PHP: <?php class A implements \ArrayAccess { public $values = []; public function setTest() { $this['test'] = 'test'; } public function offsetGet($offset) { return $this->values[$offset]; } public function offsetSet($offset, $value) { $this->values[$offset] = $value; } public function offsetExists($offset) { return array_key_exists($offset, $this->values); } public function offsetUnset($offset) { unset($this->values[$offset]); } } $test = new A; $test->setTest(); echo $test['test']; there will be a red background for the line $this['test'] = 'test', saying "Cannot re-assign $this". But that is in fact possible due to $this being an instance of class implementing the ArrayAccess interface, thus allowing it to be accessed as array. Please look in to this, many frameworks use this kind of access heavily for forms, components etc. and it is very distracting. Thanks and have a nice day!