Bug 346876

Summary: Parsing error when assing using array syntax to $this 'Cannot re-assign $this'
Product: [Applications] kdevelop Reporter: Andrew Udvare <audvare>
Component: Language Support: PHPAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal CC: alexander, jan.pavlicek
Priority: NOR    
Version: git master   
Target Milestone: ---   
Platform: Compiled Sources   
OS: All   
URL: http://i.imgur.com/1u9a7By.png
Latest Commit: Version Fixed In: 5.1.0

Description Andrew Udvare 2015-04-29 00:15:52 UTC
Laravel seems to use this valid syntax (PHP interpreter accepts it):

$this['env'] = 'some value';

as opposed to using the -> because -> would resolve to a property on the class whereas [] notation will call the \ArrayAccess methods (offsetGet(), offsetSet(), etc).

Reproducible: Always

Steps to Reproduce:
1. Create a file in project with these contents and allow parser to run.

<?php
class Test implements \ArrayAccess
{
    private $a = array();

    // ArrayAccess methods
    function offsetExists($key)
    {
        return array_key_exists($key, $this->a);
    }
    function offsetGet($key)
    {
        return $this->a[$key];
    }
    function offsetSet($key, $val)
    {
        $this->a[$key] = $val;
    }
    function offsetUnset($key)
    {
        unset($this->a[$key]);
    }

	/**
	 * @return string
	 */
    function useThisWithArraySyntax()
    {
		$this['key'] = 'some value';
    }
}

2. Note that $this in the useThisWithArraySyntax() method is red underlined.

Actual Results:  
$this is incorrectly underlined as invalid syntax: 'Cannot re-assign $this'

Expected Results:  
$this with array (bracket) notation should be considered valid syntax. It does something other than what -> (or ::) does in PHP.

Real file: https://github.com/laravel/framework/blob/5.0/src/Illuminate/Foundation/Application.php#L435
Comment 1 Jan Pavlicek 2016-05-10 13:38:44 UTC
I second this bug, using \ArrayAccess all the time and also Nette Framework which I use does utilize this language spec - the red underline is very confusing.
Comment 2 Alexander Zhigalin 2017-02-28 08:45:02 UTC
*** Bug 373414 has been marked as a duplicate of this bug. ***