PHPackages                             lukasz93p/class-visibility - 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. lukasz93p/class-visibility

ActiveLibrary

lukasz93p/class-visibility
==========================

Private and protected classes for PHP.

1.1.1(4y ago)01.5kMITPHPPHP ^8.0

Since Feb 27Pushed 4y agoCompare

[ Source](https://github.com/Lukasz93P/classes-visibility)[ Packagist](https://packagist.org/packages/lukasz93p/class-visibility)[ RSS](/packages/lukasz93p-class-visibility/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (4)Dependencies (4)Versions (4)Used By (0)

class-visibility
================

[](#class-visibility)

Private and protected classes for PHP.
--------------------------------------

[](#private-and-protected-classes-for-php)

Private and protect classes known from some strongly typed languages helps keep cleaner dependencies and promotes good code organization.

### Private classes

[](#private-classes)

Private classes can only be used by classes defined inside the exact same namespace. Ex. class `SomeNamespace\Abc\SomeClassName` can be used by `SomeNamespace\Abc\OtherClass` but **not** by `SomeNamespace\Abc\NestedNamespace\SomeClassFromNestedNamespace`, and cannot be used by any class from outside of `SomeNamespace\Abc` namespace.

### Protected classes

[](#protected-classes)

Protected classes work slightly differently than in Java. Protected class can be used inside the exact same namespace, like private class, but it also can be used by classes from nested namespaces. Ex. class `SomeNamespace\Abc\SomeClassName` can be used by `SomeNamespace\Abc\OtherClass` **and** by `SomeNamespace\Abc\NestedNamespace\SomeClassFromNestedNamespace`

### Declaring visibility

[](#declaring-visibility)

All you need to do to declare class visibility is to add the attribute.

```
use Lukasz93P\ClassVisibility\Visibility\Visibilities\PrivateVisibility;

#[PrivateVisibility(self::class)]
class ClassWithPrivateVisibility
{
}
```

```
use Lukasz93P\ClassVisibility\Visibility\Visibilities\ProtectedVisibility;

#[ProtectedVisibility(self::class)]
class ClassWithProtectedVisibility
{
}
```

**Classes with no visibility attribute defined are considered public.**

### Check violations

[](#check-violations)

To check if a given namespace violates visibility rules run

```
vendor/bin/class-visibility check
```

or

```
vendor/bin/class-visibility check ,,
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity60

Established project with proven stability

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.

###  Release Activity

Cadence

Every ~77 days

Total

3

Last Release

1748d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e1a446071d08efd8bbc3de614e529d7157a8828bc37e61a41a681af34654137?d=identicon)[Lukasz93P](/maintainers/Lukasz93P)

---

Tags

visibilityprivate classes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lukasz93p-class-visibility/health.svg)

```
[![Health](https://phpackages.com/badges/lukasz93p-class-visibility/health.svg)](https://phpackages.com/packages/lukasz93p-class-visibility)
```

###  Alternatives

[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[kartik-v/yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.

743.1M27](/packages/kartik-v-yii2-dynagrid)[php-soap/wsdl

Deals with WSDLs

173.5M12](/packages/php-soap-wsdl)[php-soap/wsdl-reader

A WSDL reader in PHP

212.3M9](/packages/php-soap-wsdl-reader)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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