How to highlight dynamic property invocation in PhpStorm in a different color than?

204 Views Asked by At

I like for my PhpStorm (version 8.0.3) to show potential errors and bugs in glaring colors in order to prevent time from being wasted.

Recently, I often discover myself doing this kind of typo:

$this->$someExistingProperty = 'fnord';

This obviously means something entirely different than:

$this->someExistingProperty = 'fnord';

Is it possible to configure PhpStorm that it shows dynamically invoked properties and methods in a different color, e.g. pink?

It also would help if only the $ would appear in a different color, just like the semicolon.

Right now, I see it this way:

Screenshot of current syntax highlighting

Can I configure it and if so, where? I have searched through the Colors & Fonts tab for PHP but so far, without luck.

2

There are 2 best solutions below

3
On

I didn't found any options to highlight the line you want, but you can highlight the other identifier (in bold by example) in the Language Defaults or PHP menu:

enter image description here

The result:

enter image description here

0
On

It depends on your editor color scheme.

This is what I see with my custom scheme (based on Default).

<?php
class TestClass
{
    protected $someVar;
    protected $anotherVar;

    public function ddd()
    {
        $someVar = 'anotherVar';

        $this->someVar = 123;
        $this->$someVar = 222;

    }
}

$z = new TestClass();
$z->ddd();

enter image description here

As you can see it's easy to tell what is what here.

The styles are "Identifier" and "Variable".


Although in general IDE should warn you about your $this->$someExistingProperty code -- because for that you have to have local $someExistingProperty variable defined...

This is what I see in v9 (note commented local $someVar line):

enter image description here


P.S. In v9 (currently in EAP stage but will be released soon (within few weeks -- sometime in July)) few more styles were introduced, e.g. "Instance Field" which should allow you to differentiate between local variable and class property.