Download the PHP package jonbaldie/phpstan-extension-accessing-globals without Composer

On this page you can find all versions of the php package jonbaldie/phpstan-extension-accessing-globals. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpstan-extension-accessing-globals

PHPStan Extension: Accessing Globals

This project is a PHPStan extension for detecting code that accesses or modifies globally shared data in PHP, a common source of bugs and a violation of functional programming principles.

It helps you write cleaner, more predictable code by ensuring that functions and methods receive all their dependencies explicitly.

Features

This extension provides a set of rules to enforce restrictions on accessing and modifying global and superglobal variables:

The extension also includes a more "opinionated" set of rules for teams that want to enforce a stricter, more functional style of programming:

Installation

You can install this extension via Composer:

Usage

This extension comes with three pre-defined rule sets.

Default (Pragmatic) Rules

This is the recommended configuration for most projects. It prevents the use of the global keyword and modification of $GLOBALS, while allowing superglobals to be accessed and modified in the root scope (e.g., in your index.php file).

To enable the default rules, include rules.neon in your project's phpstan.neon configuration:

This enables the following rules:

Note: A single line of code may trigger multiple rules. For example, global $db; $db = new PDO(...) will report both accessing the global variable AND modifying it, since these represent distinct problems that need different refactoring approaches.

Strict Rules

This configuration is for projects that want to enforce the highest level of strictness. It completely forbids any interaction with global or superglobal variables anywhere in your codebase.

To enable the strict rules, include rules-strict.neon instead:

This enables the following rules:

Opinionated Rules

This is the strictest rule set, designed for projects that want to enforce a purely functional style where all dependencies are explicit. It helps eliminate hidden dependencies, side effects, and mutations.

To enable the opinionated rules, include rules-opinionated.neon:

This enables the following rules:

Working with Legacy Code

If you're applying this extension to an existing codebase with heavy global variable usage, here's what to expect:

Error Volume: A 3,000-line legacy script might have 50-100+ errors from the default rules. This is expected and represents real technical debt.

Recommended Approach:

  1. Start with the default rules (rules.neon) - they're pragmatic and focus on the most problematic patterns
  2. Focus on global keyword usage first - this reveals which functions share hidden state with each other
  3. Tackle superglobal usage in functions next - superglobals at the top-level (e.g., in index.php) are allowed, but inside functions they create hidden dependencies
  4. Skip the opinionated rules initially - they'll flag hundreds of issues like time(), rand(), and define() usage that aren't the critical problems

What each rule catches:

The goal is to make dependencies explicit through function parameters and return values.

Custom Configuration

If you want to enable only a specific set of rules, you can copy the ones you need from the extension's config directory into your own phpstan.neon file.

Examples

This extension is designed to catch problematic patterns in your code. Here's what each rule detects:

Default Rules (rules.neon)

Strict Rules (rules-strict.neon)

Opinionated Rules (rules-opinionated.neon)

The key principle: Make all dependencies explicit through function parameters and return values.


All versions of phpstan-extension-accessing-globals with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jonbaldie/phpstan-extension-accessing-globals contains the following files

Loading the files please wait ...