PHPackages                             zeleniy/phpcs-backslash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zeleniy/phpcs-backslash

ActivePhpcodesniffer-standard[Utility &amp; Helpers](/categories/utility)

zeleniy/phpcs-backslash
=======================

PHP CodeSniffer sniff that checks if all global PHP functions are fully qualified

07PHP

Since Dec 4Pushed 1y agoCompare

[ Source](https://github.com/zeleniy/phpcs-backslash)[ Packagist](https://packagist.org/packages/zeleniy/phpcs-backslash)[ RSS](/packages/zeleniy-phpcs-backslash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

My PHP CodeSniffer sniff
========================

[](#my-php-codesniffer-sniff)

Sniff
-----

[](#sniff)

`FullyQualifiedGlobalFunctions`, a PHP CodeSniffer sniff that checks if the global PHP functions are missing a backslash.

### Why?:

[](#why)

Function resolution without the backslash forces the PHP globals to verify for each function call if function belongs to current namespace or the global namespace. With the backslash PHP does not check the current namespace and therefore execution is faster.

Install
-------

[](#install)

Install it with `composer require --dev soderlind/coding-standard`

Use
---

[](#use)

Create a `phpcs.xml.dist` in the project root folder. Something like this:

```

	/vendor/*

		Checks if global PHP functions are fully qualified.

```

If you set `onlyOptimizedFunctions` to true, backslash will only be added to [optimized functions](https://github.com/soderlind/coding-standard/blob/master/FullyQualifiedGlobalFunctions/Sniffs/FullyQualifiedGlobalFunctionsSniff.php#L21-L61).

[![#f03c15](https://camo.githubusercontent.com/0f961518a7ec2afddbe358d250696841250391fd10d08f87047ec0e63321be23/68747470733a2f2f706c616365686f6c642e69742f31352f6630336331352f3030303030303f746578743d2b)](https://camo.githubusercontent.com/0f961518a7ec2afddbe358d250696841250391fd10d08f87047ec0e63321be23/68747470733a2f2f706c616365686f6c642e69742f31352f6630336331352f3030303030303f746578743d2b) **NOTE**, `` doesn't work atm. If you want to add backslash only to the optimized functions, [use the command line](#command-line)

### Check

[](#check)

`./vendor/bin/phpcs -p test.php`

```
FILE: test.php
--------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------
 5 | ERROR | [x] Function array_diff() should be referenced via a fully
   |       |     qualified name, e.g.: \array_diff()
 7 | ERROR | [x] Function in_array() should be referenced via a fully qualified
   |       |     name, e.g.: \in_array()
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

```

### Fix

[](#fix)

`./vendor/bin/phpcbf -p test.php`

```
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
test.php                                              2      0
----------------------------------------------------------------------
A TOTAL OF 2 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------

```

### Command line

[](#command-line)

Instead of adding the rule to your `phpcs.xml.dist` file, you can run it from the command line, e.g.:

`./vendor/bin/phpcbf -p test.php --standard=FullyQualifiedGlobalFunctions --runtime-set onlyOptimizedFunctions true`

License
-------

[](#license)

MIT License

Copyright (c) 2020 Per Søderlind

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2543ef171200f8f297d4ede6c1b2fbb74e2d53532a7e8dc0d8b153b70620f013?d=identicon)[zeleniy](/maintainers/zeleniy)

---

Top Contributors

[![soderlind](https://avatars.githubusercontent.com/u/1649452?v=4)](https://github.com/soderlind "soderlind (43 commits)")

### Embed Badge

![Health badge](/badges/zeleniy-phpcs-backslash/health.svg)

```
[![Health](https://phpackages.com/badges/zeleniy-phpcs-backslash/health.svg)](https://phpackages.com/packages/zeleniy-phpcs-backslash)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
