Shared coding conventions allow teams to collaborate efficiently. Defining and using global variables and global functions, when the convention dictates OOP can be confusing and difficult to use properly for multiple reasons:

Instead of being declared globally, such variables and functions should be moved into a class, potentially marked static, so they can be used without a class instance.

This rule checks that only Object Oriented Programming is used and that no functions or procedures are declared outside of a class.

Noncompliant Code Example

<?php

$name = "Bob"; // Noncompliant

function doSomething($arg) {   // Noncompliant
  //...
}

class MyClass {
    //...
}

Compliant Solution

<?php 
class MyClass {

  public static $name = "Bob"; // Compliant

  public static function doSomething($arg) {              // Compliant
    //...
  }
  //...
}