PHPackages                             thomas-squall/utils - 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. thomas-squall/utils

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

thomas-squall/utils
===================

Generic Utilities for PHP

0.6.6(6y ago)0143MITPHP

Since Dec 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ThomasSquall/PHPUtils)[ Packagist](https://packagist.org/packages/thomas-squall/utils)[ RSS](/packages/thomas-squall-utils/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

Utils for php
=============

[](#utils-for-php)

List of available functions
---------------------------

[](#list-of-available-functions)

1. [array\_to\_object](#array_to_object)
2. [json\_to\_object](#json_to_object)
3. [parse\_args](#parse_args)
4. [get](#get)
5. [dispose](#dispose)
6. [is\_cli](#is_cli)

#### Other contained Repositories

[](#other-contained-repositories)

1. [String utils](https://github.com/ThomasSquall/PHPStringUtils)
2. [File utils](https://github.com/ThomasSquall/PHPFileUtils)

### array\_to\_object

[](#array_to_object)

#### Description

[](#description)

Returns an object out of an array. Note that only fields corresponding to the array keys will be returned.

#### Definition

[](#definition)

array\_to\_object($array, $object)

Where:

1. $array is the array to convert
2. $object is the object or class to be returned
3. $add\_not\_existing\_properties is used to choose whether to add properties not defined in the class to the object

#### Usage

[](#usage)

```
class Person {
    public $name;
    public $age;
}

$array = [
    "name" => "MyName",
    "surname" => "MySurname",
    "age" => 27
];

print_r(array_to_object($array, "Person"));
echo PHP_EOL;
print_r(array_to_object($array, "Person", true));
```

This will print:

```
Person Object ( [name] => MyName [age] => 27 )
Person Object ( [name] => MyName [age] => 27 [surname] => MySurname )
```

### json\_to\_object

[](#json_to_object)

#### Description

[](#description-1)

Returns an object out of a json string. Note that only fields corresponding to the json keys will be returned unless you pass $add\_not\_existing\_properties to true.

#### Definition

[](#definition-1)

json\_to\_object($json, $object, $add\_not\_existing\_properties = false)

Where:

1. json is the json to convert
2. $object is the object or class to be returned
3. $add\_not\_existing\_properties is used to choose whether to add properties not defined in the class to the object

#### Usage

[](#usage-1)

```
class Person {
    public $name;
    public $age;
}

$json = '{
    "name": "MyName",
    "surname": "MySurname",
    "age": 27
}';

print_r(array_to_object($json, "Person"));
echo PHP_EOL;
print_r(array_to_object($json, "Person", true));
```

This will print:

```
Person Object ( [name] => MyName [age] => 27 )
Person Object ( [name] => MyName [age] => 27 [surname] => MySurname )
```

### parse\_args

[](#parse_args)

#### Description

[](#description-2)

Build a new array out of the $options one with defaults values taken from $defaults when nothing is found.

#### Definition

[](#definition-2)

parse\_args($options, $defaults)

Where:

1. $options is the array to be parsed and used to build the new array
2. $defaults is the array containing default values to use when no correspondence is found

#### Usage

[](#usage-2)

```
$defaults = [
    "name" => "MyName",
    "surname" => "MySurname",
    "age" => 27
];

$person = [
    "name" => "MyRealName",
    "surname" => "MyRealSurname"
];

print_r(parse_args($person, $defaults));
```

This will print:

```
Array ( [name] => MyRealName [surname] => MyRealSurname [age] => 27 )
```

### get

[](#get)

#### Description

[](#description-3)

Checks if the provided value is empty and, if it is, the default value will be returned. The value itself will be returned otherwise.

#### Definition

[](#definition-3)

get($value, $default = "")

Where:

1. $value is the value to be checked to be empty or not
2. $default is the value to pass in case the first is empty. Defaulted to empty string

#### Usage

[](#usage-3)

```
$value = "";

echo get($value, "hello");
```

This will print:

```
hello
```

### dispose

[](#dispose)

#### Description

[](#description-4)

Disposes any item.

#### Definition

[](#definition-4)

dispose(&amp;$item)

Where:

1. $item is the item to be disposes

#### Usage

[](#usage-4)

```
$array = [
    "Hello",
    " ",
    "world"
];

dispose($array);
```

### is\_cli

[](#is_cli)

#### Description

[](#description-5)

Returns true if the script is running in the cli or not.

#### Definition

[](#definition-5)

is\_cli()

#### Usage

[](#usage-5)

```
if (is_cli())
    echo "This script is running in the shell";
else
    echo "This script is not running in the shell";
```

More utilities coming...
------------------------

[](#more-utilities-coming)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~47 days

Recently: every ~6 days

Total

6

Last Release

2458d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7748020?v=4)[Thomas Cocchiara](/maintainers/ThomasSquall)[@ThomasSquall](https://github.com/ThomasSquall)

---

Top Contributors

[![ThomasSquall](https://avatars.githubusercontent.com/u/7748020?v=4)](https://github.com/ThomasSquall "ThomasSquall (11 commits)")

---

Tags

arrayjsonphputilsutils-library

### Embed Badge

![Health badge](/badges/thomas-squall-utils/health.svg)

```
[![Health](https://phpackages.com/badges/thomas-squall-utils/health.svg)](https://phpackages.com/packages/thomas-squall-utils)
```

###  Alternatives

[phptars/tars2php

php代码自动生成工具

1211.1k5](/packages/phptars-tars2php)

PHPackages © 2026

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