https://bugs.kde.org/show_bug.cgi?id=373414

            Bug ID: 373414
           Summary: Accessing $this as an array marks the code as syntax
                    error, even though it is a correct syntax in PHP
           Product: kdevelop
           Version: 5.0.3
          Platform: Archlinux Packages
                OS: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: Language Support: PHP
          Assignee: kdevelop-bugs-n...@kde.org
          Reporter: jan.pavli...@centrum.cz
  Target Milestone: ---

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!

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to