PHPackages                             jitsu/util - 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. jitsu/util

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

jitsu/util
==========

General-purpose utilities for PHP

0.1.2(10y ago)01102MITPHPPHP &gt;=5.4.0

Since Sep 19Pushed 10y ago1 watchersCompare

[ Source](https://github.com/bdusell/jitsu-util)[ Packagist](https://packagist.org/packages/jitsu/util)[ RSS](/packages/jitsu-util/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (2)

jitsu/util
----------

[](#jitsuutil)

This package includes a number of general-purpose utilities for PHP.

This package is part of [Jitsu](https://github.com/bdusell/jitsu).

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

[](#installation)

Install this package with [Composer](https://getcomposer.org/):

```
composer require jitsu/util
```

Namespace
---------

[](#namespace)

The class is defined under the namespace `Jitsu`.

API
---

[](#api)

### class Jitsu\\Util

[](#class-jitsuutil)

A collection of general-purpose static methods.

#### Util::str($var)

[](#utilstrvar)

Get the string representation of a value.

Returns the result of the built-in `print_r` function.

Type**`$var`**`mixed`returns`string`#### Util::repr($var)

[](#utilreprvar)

Get a PHP-code representation of a value as a string.

Returns the result of the built-in `var_export` function.

Type**`$var`**`mixed`returns`string`#### Util::p($args...)

[](#utilpargs)

Print values to *stdout*. Intended for debugging.

Prints all of its arguments to **stdout** as PHP code using `var_export`, separated by spaces and terminated with a newline. Returns the last argument, which makes it easy to insert a call into the middle of an expression to print an intermediate value.

TypeDescription**`$args,...`**`mixed`returns`mixed`The last argument.#### Util::template($filename, $variables)

[](#utiltemplatefilename-variables)

Transclude a PHP file in a private variable scope.

This `include`s a file within its own variable scope, which may optionally be populated with an array of values.

Type**`$filename`**`string`**`$variables`**`array#### Util::has($arr\_or\_obj, $key\_or\_name)

[](#utilhasarr_or_obj-key_or_name)

Tell whether an array or object has a certain key or property.

Unlike `isset`, this works even when the value in question is `null`.

Type**`$arr_or_obj`**`array**`$key_or_name`**`intreturns`bool`#### Util::get($arr\_or\_obj, $key\_or\_name)

[](#utilgetarr_or_obj-key_or_name)

Get the value under a key in an array or a property in an object.

Optionally provide a default value to use if the key or property does not exist.

Type**`$arr_or_obj`**`array**`$key_or_name`**`intreturns`mixed`#### Util::set($arr\_or\_obj, $key\_or\_name, $value)

[](#utilsetarr_or_obj-key_or_name-value)

Set a key in an array or a property in an object to some value.

Type**`$arr_or_obj`**`array**`$key_or_name`**`int**`$value`**`mixed`#### Util::hasKey($array, $key)

[](#utilhaskeyarray-key)

Determine whether an array contains a certain key.

Works even if the value is `null`.

Type**`$array`**`array`**`$key`**`intreturns`bool`#### Util::getKey($array, $key, $default = null)

[](#utilgetkeyarray-key-default--null)

Get a value from an array, or a default value if the key is not present.

Type**`$array`**`array`**`$key`**`int**`$default`**`mixed`returns`mixed`#### Util::hasProp($obj, $name)

[](#utilhaspropobj-name)

Determine whether an object has a property with a certain name.

Type**`$obj`**`object`**`$name`**`string`returns`bool`#### Util::getProp($obj, $name, $default = null)

[](#utilgetpropobj-name-default--null)

Get the value of a property in an object or a default value if the object does not have a property by that name.

Type**`$obj`**`object`**`$name`**`string`**`$default`**`mixed`returns`mixed`### class Jitsu\\MetaUtil

[](#class-jitsumetautil)

Utilities for introspection and reflection.

#### MetaUtil::constantExists($name)

[](#metautilconstantexistsname)

Determine whether a constant by a certain name has been defined.

Type**`$name`**`string`returns`bool`#### MetaUtil::functionExists($name)

[](#metautilfunctionexistsname)

Determine whether a function by a certain name has been defined.

Type**`$name`**`string`returns`bool`#### MetaUtil::classExists($name)

[](#metautilclassexistsname)

Determine whether a class by a certain name has been defined.

Type**`$name`**`string`returns`bool`#### MetaUtil::hasMethod($obj, $name)

[](#metautilhasmethodobj-name)

Determine whether an object has a method by a certain name.

Type**`$obj`**`object`**`$name`**`string`returns`bool`#### MetaUtil::hasStaticMethod($class\_name, $name)

[](#metautilhasstaticmethodclass_name-name)

Determine whether a class has a static method by a certain name.

Type**`$class_name`**`string`**`$name`**`string`returns`bool`#### MetaUtil::callFunction($name, $args...)

[](#metautilcallfunctionname-args)

Call a function by a certain name.

TypeDescription**`$name`**`string`**`$args,...`**`mixed`Arguments to the function.returns`mixed`Whatever is returned by the called function.#### MetaUtil::callMethod($obj, $name, $args...)

[](#metautilcallmethodobj-name-args)

Call a method by a certain name on an object.

TypeDescription**`$obj`**`object`**`$name`**`string`**`$args,...`**`mixed`Arguments to the method.returns`mixed`Whatever is returned by the called method.#### MetaUtil::callStaticMethod($class\_name, $name, $args...)

[](#metautilcallstaticmethodclass_name-name-args)

Call a static method by a certain name from a certain class.

TypeDescription**`$class_name`**`string`**`$name`**`string`**`$args,...`**`mixed`Arguments to the method.returns`mixed`Whatever is returned by the called method.#### MetaUtil::callConstructor($class\_name, $args...)

[](#metautilcallconstructorclass_name-args)

Call the constructor of a class by a certain name.

TypeDescription**`$class_name`**`string`**`$args,...`**`mixed`Arguments to the constructor.returns`object`The newly constructed object, as if `new` had been used.#### MetaUtil::applyFunction($name, $args)

[](#metautilapplyfunctionname-args)

Call a function with an array of arguments.

Type**`$name`**`string`**`$args`**`array`returns`mixed`#### MetaUtil::applyMethod($obj, $name, $args)

[](#metautilapplymethodobj-name-args)

Call a method on an object with an array of arguments.

Type**`$obj`**`object`**`$name`**`string`**`$args`**`array`returns`mixed`#### MetaUtil::applyStaticMethod($class\_name, $name, $args)

[](#metautilapplystaticmethodclass_name-name-args)

Call a static method with an array of arguments.

Type**`$class_name`**`string`**`$name`**`string`**`$args`**`array`returns`mixed`#### MetaUtil::applyConstructor($class\_name, $args)

[](#metautilapplyconstructorclass_name-args)

Call a class constructor with an array of arguments.

TypeDescription**`$class_name`**`string`**`$args`**`array`returns`object`The newly constructed object, as if `new` had been used.#### MetaUtil::typeName($value)

[](#metautiltypenamevalue)

Get the class or type of a value as a string.

Type**`$value`**`mixed`returns`string`#### MetaUtil::publicMethods($obj)

[](#metautilpublicmethodsobj)

Enumerate all of the public methods of an object.

Type**`$obj`**`object`returns`\ReflectionMethod[]`#### MetaUtil::registerAutoloader($callback)

[](#metautilregisterautoloadercallback)

Add a callback to the chain of autoloader callbacks.

Not necessary if Composer is used.

Type**`$callback`**`callable`#### MetaUtil::autoloadNamespace($namespace, $dirs)

[](#metautilautoloadnamespacenamespace-dirs)

Register an autoloader which maps a namespace to one or more filesystem directories.

Not necessary if Composer is used.

Type**`$namespace`**`string`**`$dirs`**`string### class Jitsu\\Util\\Lazy

[](#class-jitsuutillazy)

A base class for defining lazily-instantiated classes.

Lazy objects behave just like those of another class, except they are not instantiated until the first time one of their members is accessed.

Subclass this class and define `const T` in the subclass as the name of the proxied class. The subclass is the lazy class.

#### new Lazy()

[](#new-lazy)

#### $lazy-&gt;\_\_call($name, $args)

[](#lazy-__callname-args)

#### $lazy-&gt;\_\_get($name)

[](#lazy-__getname)

#### $lazy-&gt;\_\_set($name, $value)

[](#lazy-__setname-value)

#### $lazy-&gt;\_\_isset($name)

[](#lazy-__issetname)

#### $lazy-&gt;\_\_unset($name)

[](#lazy-__unsetname)

#### $lazy-&gt;\_\_toString()

[](#lazy-__tostring)

#### $lazy-&gt;\_\_clone()

[](#lazy-__clone)

#### $lazy-&gt;\_\_invoke()

[](#lazy-__invoke)

#### $lazy-&gt;\_\_debugInfo()

[](#lazy-__debuginfo)

#### $lazy-&gt;\_\_sleep()

[](#lazy-__sleep)

#### $lazy-&gt;\_\_wakeup()

[](#lazy-__wakeup)

#### $lazy-&gt;instantiate()

[](#lazy-instantiate)

Instantiate the underlying object without needing to reference one of its members.

#### $lazy-&gt;isInstantiated()

[](#lazy-isinstantiated)

Tell whether the underlying object has been instantiated.

Typereturns`bool`### trait Jitsu\\Util\\Singleton

[](#trait-jitsuutilsingleton)

A mixin for creating singleton classes.

Override `instantiate` to return some object. All methods of that object become available as static methods of the derived class, and the object is only instantiated when one of these methods is called.

#### $singleton-&gt;instantiate() \[protected\]

[](#singleton-instantiate-protected)

Override this method to return the singleton instance.

Typereturns`object`#### Singleton::instance()

[](#singletoninstance)

Get the singleton instance.

Typereturns`object`#### Singleton::\_\_callStatic($name, $args)

[](#singleton__callstaticname-args)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

3663d ago

### Community

Maintainers

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

---

Top Contributors

[![bdusell](https://avatars.githubusercontent.com/u/5336190?v=4)](https://github.com/bdusell "bdusell (6 commits)")

---

Tags

helper-functionsphputilityreflectionlazysingletonintrospection

### Embed Badge

![Health badge](/badges/jitsu-util/health.svg)

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

###  Alternatives

[phpdocumentor/reflection-common

Common reflection classes used by phpdocumentor to reflect the code structure

9.1k706.8M26](/packages/phpdocumentor-reflection-common)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4875.5M16](/packages/voku-arrayy)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)

PHPackages © 2026

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