Bug 346876 - Parsing error when assing using array syntax to $this 'Cannot re-assign $this'
Summary: Parsing error when assing using array syntax to $this 'Cannot re-assign $this'
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: PHP (show other bugs)
Version: git master
Platform: Compiled Sources All
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL: http://i.imgur.com/1u9a7By.png
Keywords:
: 373414 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-04-29 00:15 UTC by Andrew Udvare
Modified: 2017-03-07 08:50 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.1.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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. ***