1.2.681. Method Property Confusion

There might be confusion between a property and a method when they bear the same name. While it is a valid PHP syntax, using the same name for properties and methods leads to possible confusion in the code.

<?php

class x {
     private $query = 1;

     function query() : void {}

     function foo() {
             // The property is useless : it may be a call to the method, in fact
             $this->query;

             // The method call returns nothing : PHP replaces it with NULL.
             $c = $this->query();
     }
}

?>

1.2.681.1. Suggestions

  • Change the name : either the property, or the method

1.2.681.2. Specs

Short name

Classes/MethodPropertyConfusion

Rulesets

All, Changed Behavior, Semantics

Exakat since

2.5.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud