PHPackages                             sevavietl/type-casting - 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. sevavietl/type-casting

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sevavietl/type-casting
======================

v0.1(7y ago)43MITPHPPHP &gt;=7.1

Since Nov 3Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Sevavietl/TypeCasting)[ Packagist](https://packagist.org/packages/sevavietl/type-casting)[ RSS](/packages/sevavietl-type-casting/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

TypeCasting - kind of explicit type casting in PHP
==================================================

[](#typecasting---kind-of-explicit-type-casting-in-php)

[![Build Status](https://camo.githubusercontent.com/fb445402e3a74538c856eb65ee9ddab7b1a7990e497bac987fb0d170d0b560f6/68747470733a2f2f7472617669732d63692e636f6d2f53657661766965746c2f5479706543617374696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Sevavietl/TypeCasting)[![Coverage Status](https://camo.githubusercontent.com/94838416c690d6d9cfa3a75eeed30c9d7a916c9a6e96f7534fea10c686b38485/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f53657661766965746c2f5479706543617374696e672f62616467652e737667)](https://coveralls.io/github/Sevavietl/TypeCasting)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

Neither real [covariance](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) in method return type hints, nor [explicit type casting](https://www.baeldung.com/java-type-casting) are supported in PHP.

Sometimes it is useful to downcast object, so PhpStorm or PHPStan stop complaining about absent methods or mismatched types.

Usually [@var](http://docs.phpdoc.org/references/phpdoc/tags/var.html) tag used for this. But as with all phpdoc tags in regard of typing, this is simply telling your IDE or static analyzer tool to take your honest word that you know for sure the type of the stuff.

Whereas with actual type casting (like say in java, C# or even in PHP, but only for primitives) you can be sure that object (or primitive) is "castable" into specified type, or end up with exception.

So you can plug `\TypeCasting\TypeCasting` trait into your class (but only one per inheritance chain) and then use `cast` method that is a bit like [`Java.lang.Class.cast`](https://www.tutorialspoint.com/java/lang/class_cast.htm) method (but of course this is oversimplified comparison).

[![downcasting](images/downcasting.gif)](images/downcasting.gif)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2748d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d447606cedb25aa0f2e4a57788d793bb46215aadaa5841b8ccf66f9477e5267?d=identicon)[sevavietl](/maintainers/sevavietl)

---

Top Contributors

[![Sevavietl](https://avatars.githubusercontent.com/u/1844827?v=4)](https://github.com/Sevavietl "Sevavietl (2 commits)")

---

Tags

downcastphptypecasttypes

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sevavietl-type-casting/health.svg)

```
[![Health](https://phpackages.com/badges/sevavietl-type-casting/health.svg)](https://phpackages.com/packages/sevavietl-type-casting)
```

###  Alternatives

[surfsidemedia/shoppingcart

Laravel Shoppingcart

1712.6k](/packages/surfsidemedia-shoppingcart)

PHPackages © 2026

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