PHPackages                             itarato/var-check - 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. itarato/var-check

ActiveLibrary

itarato/var-check
=================

Accessing properties, keys and instance methods without checking them all the time.

v2.x-dev(10y ago)02.9k↓100%MITPHP

Since Feb 23Pushed 10y agoCompare

[ Source](https://github.com/itarato/var-check)[ Packagist](https://packagist.org/packages/itarato/var-check)[ RSS](/packages/itarato-var-check/feed)WikiDiscussions v2 Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

VarCheck
========

[](#varcheck)

[![Build Status](https://camo.githubusercontent.com/3d635a4a925f320dbeb58044d7fed1a4f0ece88c11ffff8fc6cd0719a1bbbfff/68747470733a2f2f7472617669732d63692e6f72672f6974617261746f2f7661722d636865636b2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/itarato/var-check)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e595dbbf7e914c5f1eb9b835a362e4e3f24ade5ccbdfa8ecf9e7dfaece06a229/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6974617261746f2f7661722d636865636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/itarato/var-check/?branch=master)

[![Codeship Status for itarato/var-check](https://camo.githubusercontent.com/e97442ff183a85ef3194bffb73285a3799bd33bed9691a2969381e9a8b8a6898/68747470733a2f2f7777772e636f6465736869702e696f2f70726f6a656374732f66613966323564302d336439322d303133322d633164322d3036656232366136653630342f737461747573)](https://www.codeship.io/projects/43300)

Changelog
---------

[](#changelog)

\#Version 2

- Use of PSR-4 autoading:

```
require_once __DIR__ . '/vendor/autoload.php';
use itarato\VarCheck\VC;
```

- Instance creation:

```
VC::make($variable);
```

- VarCheck methods got underscore (avoiding real object properties, functions or array keys):

```
VC::make($variable)->_value();
VC::make($variable)->_empty();
```

- `__call` magic method now calls the instance function of the current object:

```
class User {
  function getParent() {
    return $this->parent;
  }
}
$child = new User();
VC::make($child)->getParent()->_value();
```

Install
-------

[](#install)

- Through composer: `"require": "itarato/var-check": "2.*@dev"`

```
$ echo '{"require": {"itarato/var-check": "2.*@dev"}}' > composer.json ; composer install

```

VarCheck is a single class to verify nested complex variable without lots of isset() and exist().

To avoid multiple level of isset/exist/etc this class provides an easy way to verify nested values in a variable. Typical use case when you have a large variable, and you are not sure if it has the right index, and inside there an object, and an attribute ...

The complex variable
--------------------

[](#the-complex-variable)

```
$myComplexVar = array(1 => new stdClass());
$myComplexVar[1]->name = 'John Doe';
```

Problem to solve
----------------

[](#problem-to-solve)

```
// Get the value:
$output = isset($myComplexVar[1]) && isset($myComplexVar[1]->name) ? $myComplexVar[1]->name : $otherwise;
```

Solution
========

[](#solution)

```
$output = VC::make($myComplexVar)->_key(1)->_attr('name')->_value($otherwise);
// or even simpler:
$output = VC::make($myComplexVar)->{'1'}->name->_value($otherwise);
```

Checking if the nested value exist
----------------------------------

[](#checking-if-the-nested-value-exist)

```
VC::make($myComplexVar)->_key(1)->_attr('name')->_exist(); // TRUE;
// or:
VC::make($myComplexVar)->{'1'}->name->_exist(); // TRUE;
```

Get the nested value
--------------------

[](#get-the-nested-value)

```
VC::make($myComplexVar)->_key(1)->_attr('name')->_value(); // John Doe;
```

Call a function on the value if exist
-------------------------------------

[](#call-a-function-on-the-value-if-exist)

```
// Instead of this:
$value = isset($variable['key']['foo']->element) ? my_function($variable['key']['foo']->element) : NULL;
// Do this:
$value = VC::make($variable)->key->foo->element->my_function();
// Or:
$myClassInstance;
$value = arCheck::make($variable)->key->foo->element->call(array($myClassInstance, 'instanceFunction'));
```

Failsafe check in case it does not exist
----------------------------------------

[](#failsafe-check-in-case-it-does-not-exist)

```
VC::make($myComplexVar)->_key(1)->_attr('job')->_exist(); // FALSE;
VC::make($myComplexVar)->_key(1)->_attr('job')->_attr('title')->_exist(); // FALSE;
```

Check and value at the same time
--------------------------------

[](#check-and-value-at-the-same-time)

```
if ($value = VC::make($form_status)->_key('values')->_key('#node')->_attr('field_image')->_key(LANGUAGE_NONE)->_key(0)->_key('item')->_key('fid')->_value()) {
  // Use $value;
}
// or:
if ($value = VC::make($form_status)->values->{'#node'}->field_image->{LANGUAGE_NONE}->{'0'}->item->fid->_value()) {
  // Use $value;
}
```

Custom validation
-----------------

[](#custom-validation)

```
VC::make($myVar)->_key(3)->_attr('title')->_call(function ($v) {
  return $v > 10;
});
```

###  Health Score

25

—

LowBetter than 39% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community6

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

Unknown

Total

1

Last Release

3682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc6eae8e55920207c5e755223dc1e700381d8551c3e1edc071b140f38d29b59d?d=identicon)[itarato](/maintainers/itarato)

---

Top Contributors

[![itarato](https://avatars.githubusercontent.com/u/49009?v=4)](https://github.com/itarato "itarato (37 commits)")

### Embed Badge

![Health badge](/badges/itarato-var-check/health.svg)

```
[![Health](https://phpackages.com/badges/itarato-var-check/health.svg)](https://phpackages.com/packages/itarato-var-check)
```

PHPackages © 2026

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