PHPackages                             phpgt/typesafegetter - 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. phpgt/typesafegetter

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

phpgt/typesafegetter
====================

An interface for objects that expose type-safe getter methods.

v1.3.3(2mo ago)019.4k↑39.7%6MITPHPPHP &gt;=8.0CI passing

Since Jan 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/PhpGt/TypeSafeGetter)[ Packagist](https://packagist.org/packages/phpgt/typesafegetter)[ GitHub Sponsors](https://github.com/sponsors/PhpGt)[ RSS](/packages/phpgt-typesafegetter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (17)Used By (6)

An interface for objects that expose type-safe getter methods.
==============================================================

[](#an-interface-for-objects-that-expose-type-safe-getter-methods)

Throughout PHP.Gt repositories, wherever an object represents enclosed data, a consistent interface is used to expose the data in a type-safe manner.

---

[ ![Build status](https://camo.githubusercontent.com/8d0e5f5305af3a2a1fcad83de25f08503d8a10a225af8d2e900d7151b5416fb9/68747470733a2f2f62616467652e7374617475732e7068702e67742f74797065736166656765747465722d6275696c642e737667)](https://github.com/PhpGt/TypeSafeGetter/actions)[ ![Code quality](https://camo.githubusercontent.com/6c5bccd57740744c324836a4a64843ce8ffee057c4af028f9ab09da3b9bb4a5f/68747470733a2f2f62616467652e7374617475732e7068702e67742f74797065736166656765747465722d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/TypeSafeGetter)[ ![Code coverage](https://camo.githubusercontent.com/ab5b84edaf566fd092ab380877928c427a7510aea09e7c77364a64fcd50bb1e3/68747470733a2f2f62616467652e7374617475732e7068702e67742f74797065736166656765747465722d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/TypeSafeGetter)[ ![Current version](https://camo.githubusercontent.com/70a36ca248c71e5f8dd014e8cd4ac90c8a5e7b0be58a94f0bc907c49816a56bc/68747470733a2f2f62616467652e7374617475732e7068702e67742f74797065736166656765747465722d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/TypeSafeGetter)[ ![PHP.Gt/TypeSafeGetter documentation](https://camo.githubusercontent.com/0d9924c131f56f6eb4fd5e288bcb8d7eb8a07d5930d06c79cebcec9ebaf9d724/68747470733a2f2f62616467652e7374617475732e7068702e67742f74797065736166656765747465722d646f63732e737667)](https://www.php.gt/typesafegetter)The following methods are defined by this interface:

- `get(string $name):mixed` - A non-type-safe getter, used for getting keys that are not of an inbuilt type
- `getString(string $name):?string`
- `getInt(string $name):?int`
- `getFloat(string $name):?float`
- `getBool(string $name):?bool`
- `getDateTime(string $name):?DateTimeInterface`
- `getInstance(string $name, class-string $className):?T`

Common areas you will see this interface used:

- Database rows
- User input (from the query string or posted form data)
- Session and cookie storage
- PHP.Gt's [DataObject](https://www.php.gt/dataobject) repository.

`NullableTypeSafeGetter` trait
------------------------------

[](#nullabletypesafegetter-trait)

A lot of repositories within PHP.Gt that utilise this class were repeating the same getter code, so this trait was introduced to remove the repetition. All getter functions of the interface are implemented, introducing a protected helper function `getNullableType` which removes the repetition of checking null values before casting them. The `getNullableType` function also allows a callback to be passed as the type parameter, allowing more complex nullable types to be constructed.

Proudly sponsored by
====================

[](#proudly-sponsored-by)

[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://www.jetbrains.com/community/opensource/)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance86

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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

Every ~208 days

Recently: every ~335 days

Total

10

Last Release

69d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (10 commits)")

---

Tags

data-transfer-objectgetter-functionsinterfacetype-safety

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgt-typesafegetter/health.svg)

```
[![Health](https://phpackages.com/badges/phpgt-typesafegetter/health.svg)](https://phpackages.com/packages/phpgt-typesafegetter)
```

###  Alternatives

[qazd/text-diff

A simple text differences visualization library

38121.2k1](/packages/qazd-text-diff)

PHPackages © 2026

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