PHPackages                             ket-php/utils-safe - 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. ket-php/utils-safe

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

ket-php/utils-safe
==================

Lightweight PHP utility for safely accessing variables, handling undefined values without errors.

1.2.1(4mo ago)0132MITPHPPHP ^8.1

Since Nov 12Pushed 4mo agoCompare

[ Source](https://github.com/mikhno351/KetPHP-Safe)[ Packagist](https://packagist.org/packages/ket-php/utils-safe)[ Docs](https://github.com/mikhno351/KetPHP-Safe)[ RSS](/packages/ket-php-utils-safe/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (2)

KetSafe
=======

[](#ketsafe)

[![Packagist Version](https://camo.githubusercontent.com/e0ec0c7b77873fe3ee05323adb9738d1b18c48987ba359bbb66b67c0a41e1dbf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b65742d7068702f7574696c732d73616665)](https://camo.githubusercontent.com/e0ec0c7b77873fe3ee05323adb9738d1b18c48987ba359bbb66b67c0a41e1dbf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b65742d7068702f7574696c732d73616665)[![Packagist Downloads](https://camo.githubusercontent.com/0aaa8509c90c3cb64b84ccab5ba3e75a384fbe912e88467817798d1316da36cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b65742d7068702f7574696c732d736166653f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/0aaa8509c90c3cb64b84ccab5ba3e75a384fbe912e88467817798d1316da36cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b65742d7068702f7574696c732d736166653f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)[![Static Badge](https://camo.githubusercontent.com/d70e266076e28598d8ae3aeda67a004e4dc1f764f0d54e97ef142b529889496f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/d70e266076e28598d8ae3aeda67a004e4dc1f764f0d54e97ef142b529889496f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)

Installation
------------

[](#installation)

Install via Composer:

```
composer require ket-php/utils-safe

```

Usage
-----

[](#usage)

### Safe:

[](#safe)

```
use KetPHP\Utils\Safe;
use KetPHP\Utils\Common\Cast;

// Simple value
$value = Safe::get('Hello');
echo $value; // Hello

// Value with default
$value = Safe::get(null, 'Default');
echo $value; // Default

// Using a callable
$value = Safe::get(fn() => 123);
echo $value; // 123

// Transform only if value exists
$value = Safe::get('  John  ', 'Unknown', fn($v) => trim($v));
echo $value; // John

// Transform string function
$value = Safe::get('  John  ', 'Unknown', 'trim');
echo $value; // John

// Default value ignores transform
$value = Safe::get(null, 'Fallback', fn($v) => strtoupper($v));
echo $value; // Fallback

// Optional casting
$value = Safe::get('123', null, null, Cast::INT);
echo $value; // 123 (integer)

$data = ['known' => 'value'];

// Without null coalescing
// WARNING: PHP would normally trigger a Notice (Undefined index)
$value = Safe::get($data['unknown'], 'Default');
echo $value; // Default (PHP Notice / E_USER_WARNING is triggered)

// You can suppress the warning using the @ operator
$value = Safe::get(@$data['unknown'], 'Default');
echo $value; // Default (no warning)

// With null coalescing
// Safe and no warning
$value = Safe::get($data['unknown'] ?? null, 'Default');
echo $value; // Default
```

#### Constants for Casting:

[](#constants-for-casting)

ConstantDescription`Cast::INT`Cast to integer`Cast::FLOAT`Cast to float`Cast::STRING`Cast to string`Cast::BOOLEAN`Cast to boolean`Cast::ARRAY`Cast to array`Cast::OBJECT`Cast to object

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance74

Regular maintenance activity

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

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

Every ~10 days

Total

5

Last Release

145d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/60658acba7d28aa03d830e4708d37a7d0d797db2669bbb2e8ae0fff563df4e3e?d=identicon)[mikhno351](/maintainers/mikhno351)

---

Top Contributors

[![mikhno351](https://avatars.githubusercontent.com/u/57302726?v=4)](https://github.com/mikhno351 "mikhno351 (26 commits)")

---

Tags

phputilityhelperssafeerror handlingundefinedketphpket-phpnull-safe

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ket-php-utils-safe/health.svg)

```
[![Health](https://phpackages.com/badges/ket-php-utils-safe/health.svg)](https://phpackages.com/packages/ket-php-utils-safe)
```

###  Alternatives

[brandonwamboldt/utilphp

util.php is a collection of useful functions and snippets that you need or could use every day, designed to avoid conflicts with existing projects

1.0k538.8k12](/packages/brandonwamboldt-utilphp)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.6k2](/packages/transprime-research-piper)

PHPackages © 2026

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