PHPackages                             xeno/xeno - 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. xeno/xeno

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

xeno/xeno
=========

Dynamically changes native PHP functions into chain syntax

0.5.1(5y ago)2251GPL-2.0-onlyPHP

Since Jan 26Pushed 5y ago3 watchersCompare

[ Source](https://github.com/Mortimer333/Xeno)[ Packagist](https://packagist.org/packages/xeno/xeno)[ RSS](/packages/xeno-xeno/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)DependenciesVersions (3)Used By (0)

Xeno
====

[](#xeno)

```
  $str = new Xeno\X(' Hello world ');
  $str->trim()->substr(0,6)->tolower()->replace('ello','ow');

  $array = new Xeno\X(['s','i']);
  $array->merge(['c','k'])->implode(' ');

  echo $str->get() . ' ' . $array->get();
```

About
=====

[](#about)

This library allows user to use native PHP functions (and all functions defined globally) with chain syntax making them a lot more readable and easier to use.

Installation
============

[](#installation)

Installation method is via composer and its packagist package [xeno/xeno](https://packagist.org/packages/xeno/xeno).

```
$ composer require xeno/xeno

```

How to use
==========

[](#how-to-use)

Class is named `Xeno\X` and has one argument - the value you want to operate on.

```
 $int = new Xeno\X(1);
```

Get, Set
--------

[](#get-set)

To get a variable - use `get` method and to set it to a new value - use `set`.

```
  $array = new Xeno\X(['a']);
  $array->set(['b']);     // changing content
  print_r($array->get())  // output Array ( [0] => b )
```

Any other methods are defined by you, are `exceptions` (are native functions redefined as methods because they don't pass `value` as first argument) or are native PHP functions.

Methods
=======

[](#methods)

Replacing native functions
--------------------------

[](#replacing-native-functions)

Xeno methods are placed higher then functions in call tree. If you want to replace native php function with your own just add method with the same name.

### Example

[](#example)

```
[...] // previous elements in class
  // here we add method which is replacing substr
  public substr ( string $value )
  {
    $this->value = "sub";
    return $this;
  }
[...] // the rest of class

$str = new Xeno\X('a');
// now this methods changes our value to "sub" every time we use it
echo $str->substr()->get(); // output "sub"
```

Multi assigning
---------------

[](#multi-assigning)

When you want to create method named the same for all types (ex. cut) then add prefix to its name which will define the type it will be operating on:

- `str_` - string
- `ary_` - array
- `obj_` - object
- `int_` - only integer
- `dec_` - only float

### Example

[](#example-1)

```
[...] // previous elements in class

  public function str_cut (string $value)
  {
    // code
  }

  public function ary_cut (array $value)
  {
    // code
  }

[...] // the rest of class
```

Here I have added two methods `str_cut` and `array_cut`. Both of them you can call by `cut` and script will choose right one by its prefix and current value (or none if you call it on non supported type, in this example it would be integer). Of course you can still call them by their full name but you need to be sure that you are using right values.

```
  $str = new Xeno\X('Hello world');
  echo $str->cut( 1, 2 )->get();       // output "el"

  $ary = new Xeno\X([' Hello', 'world ']);
  print_r( $ary->cut( 1, 2 )->get() ); // output Array ( [0] => world )

  $int = new Xeno\X(1);
  echo $int->cut( 1, 2 )->get();       // Fatal error: Uncaught BadMethodCallException: cut
```

Different behavior
==================

[](#different-behavior)

Few functions (for purpose of continuity of chain) have different return values :

- `uasort` - returns sorted array not bool
- `array_walk_recursive` and `array_walk` - returns sorted array not bool
- `get_called_class` - will always return `"Xeno\X`;

When class is treated as string it will return current value:

```
  $str = new Xeno\X('x');
  echo $str; // output 'x'
```

Performance
===========

[](#performance)

The performance depends on how you call methods. Using full names of functions is much faster (3~4x) so in a case when you have thousands of operations it's better to call by using functions full names.

### Some numbers (million iterations):

[](#some-numbers-million-iterations)

Full names and native functions :

- ~0.26 s - without new instance of Xeno each iteration
- ~0.32 s - with new instance of Xeno each iteration

Full names and methods :

- ~0.11 s - without new instance of Xeno each iteration
- ~0.18 s - with new instance of Xeno each iteration

Short names and native function :

- ~0.67 s - without new instance of Xeno each iteration
- ~0.79 s - with new instance of Xeno each iteration

Short names and methods :

- ~0.68 s - without new instance of Xeno each iteration
- ~0.84 s - with new instance of Xeno each iteration

Disclaimer
==========

[](#disclaimer)

Performance
-----------

[](#performance-1)

For some comparison a million iterations of str\_replace on my computer was 0.05 s. That means you shouldn't use this library for any big operations. It's purpose is to enable chain syntax on primitives without installing new packages and having library which will be always updated. If you can install additional stuff on your server I recommend [https://github.com/nikic/scalar\_objects](https://github.com/nikic/scalar_objects) for better syntax on primitives.

Dynamic functions
-----------------

[](#dynamic-functions)

You cannot use few native function with this library because of `Cannot call dynamically` warning. Functions :

- compact
- extract

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

1930d ago

### Community

Maintainers

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

---

Top Contributors

[![Mortimer333](https://avatars.githubusercontent.com/u/34005580?v=4)](https://github.com/Mortimer333 "Mortimer333 (63 commits)")

---

Tags

syntaxChain

### Embed Badge

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

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

###  Alternatives

[scrivo/highlight.php

Server side syntax highlighter that supports 185 languages. It's a PHP port of highlight.js

71040.3M82](/packages/scrivo-highlightphp)[easybook/geshi

GeSHi - Generic Syntax Highlighter. This is an unmodified port of GeSHi project code found on SourceForge.

211.0M10](/packages/easybook-geshi)[luminous/luminous

A full featured syntax highlighting library.

521.7k2](/packages/luminous-luminous)[ramsey/pygments

A PHP wrapper for Pygments, the Python syntax highlighter, forked from kzykhys/pygments.

103.0k3](/packages/ramsey-pygments)

PHPackages © 2026

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