Skip to content

Property validUndefinedVariableNames is ignored inside else statement #238

@udovicic

Description

@udovicic

Consider the following code to be part of some template, where variable $block originates from somewhere else. Its defined somewhere else, before include was called so it indeed is available in the template:

<?php

$block->doSomething();

if (3  < 5) {
    $block->doThis();
} else {
    $block-doThat();
}

If you format ruelset to look like following:

    <rule ref="VariableAnalysis">
        <properties>
            <property name="validUndefinedVariableNames" value="block"/>
        </properties>
    </rule>

the output would be:

php,phtml test.phtml

FILE: /project/test.phtml
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 8 | WARNING | Variable $block is undefined.
----------------------------------------------------------------------

Time: 85ms; Memory: 8MB

Which is not the desired behavior.
Else statement requires special attention, but current implementation leads to false positives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions