PHPackages                             lbreme/lexepa-srl - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. lbreme/lexepa-srl

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

lbreme/lexepa-srl
=================

Class for lexing and parsing a serialized string in PHP

v1.0.3(4y ago)013MITPHPPHP &gt;=7.0.0

Since May 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lbreme/lexepa-srl)[ Packagist](https://packagist.org/packages/lbreme/lexepa-srl)[ Docs](https://github.com/lbreme/lexepa-srl)[ RSS](/packages/lbreme-lexepa-srl/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Lexepa-Srl
==========

[](#lexepa-srl)

Library for lexing and parsing a serialized string in PHP.

Installing Lexepa-Srl
=====================

[](#installing-lexepa-srl)

First, get [Composer](https://getcomposer.org/download/), if you don't already use it.

Next, run the following command inside the directory of your project:

```
composer require lbreme/lexepa-srl
```

How does it work?
=================

[](#how-does-it-work)

The Lexepa-Srl library analyzes any text string coming from the result of a serialization in PHP. During the analysis a series of callback functions are called to which are passed as arguments the elements that constitute the serialized string.

We clarify with an example, which is contained in the file [class-example-srl.php](https://github.com/lbreme/lexepa-srl/blob/main/class-example-srl.php), which to make it work is to copy in the root of your project:

```
/*
We create a class derived from the Lexepa_Srl_Abstract class, which implements all the
callback functions that will be called by the analysis of the serialized string
*/
class Example_Srl extends Lexepa_Srl_Abstract
{
	/**
	 * Begin of parsing
	 *
	 * @param string $string Original string to unserialize.
	 * @param int    $offset Initial offset.
	 */
	public function begin_parsing( $string, $offset ) {
		echo 'String serialized: ' . $string . '';
	}

	/**
	 * String length value found
	 *
	 * @param string $string_length String length value.
	 * @param int    $offset Offset of the string length value found.
	 */
	public function string_length( $string_length, $offset )
	{
		echo 'String length: ' . $string_length . '';
	}

	/**
	 * String value found
	 *
	 * @param string $string_value String value.
	 * @param int    $offset Offset of the string value found.
	 */
	public function string_value( $string_value, $offset )
	{
		echo 'String value: ' . $string_value . '';
	}

	/**
	 * Integer value found
	 *
	 * @param string $integer_value Integer value.
	 * @param int    $offset Offset of the integer value found.
	 */
	public function integer_value( $integer_value, $offset )
	{
		echo 'Integer value: ' . $integer_value . '';
	}

	/**
	 * Decimal value found
	 *
	 * @param string $decimal_value Decimal value.
	 * @param int    $offset Offset of the decimal value found.
	 */
	public function decimal_value( $decimal_value, $offset ) {
		echo 'Decimal value: ' . $decimal_value . '';
	}

	/**
	 * Boolean value found
	 *
	 * @param string $boolean_value It can be '0' or '1'.
	 * @param int    $offset Offset of the boolean value found.
	 */
	public function boolean_value( $boolean_value, $offset ) {
		echo 'Boolean value: ' . $boolean_value . '';
	}

	/**
	 * Null value found
	 *
	 */
	public function null_value() {
		echo 'Null value found' . '';
	}

	/**
	 * Number of items of the array found
	 *
	 * @param string $items_num Number of items.
	 * @param int    $offset Offset of the number of items found.
	 */
	public function array_items_num( $items_num, $offset ) {
		echo 'Number of items of the array: ' . $items_num . '';
	}

	/**
	 * End of parsing
	 *
	 * @param bool $parsing_result True if the string is unserializable.
	 */
	public function end_parsing( $parse_result )
	{
		if ( $parse_result ) {
			echo 'Good job!' . '';
		} else {
			echo 'There was an error' . '';
		}
	}

	/**
	 * Set error parsing the string.
	 *
	 * @param string $error Error parsing the string.
	 */
	public function set_error( $error )
	{
		echo $error . '';
	}
}

$example_srl = new Example_Srl();

/*
We instantiate the Lexepa-Srl library class, passing as arguments the $example_srl object
containing the callback functions and the serialized string
*/
$lexepa_srl  = new Lexepa_Srl( $example_srl, $myArraySerialized );

// Let's start the analysis
$lexepa_srl->parse_srl();

```

The result of this example is as follows:

```
String serialized: a:5:{s:4:"key1";s:22:"This is my first value";s:4:"key2";s:23:"This is my second value";s:4:"key3";i:20;s:4:"key4";b:1;s:4:"key5";N;}
Number of items of the array: 5
String length: 4
String value: key1
String length: 22
String value: This is my first value
String length: 4
String value: key2
String length: 23
String value: This is my second value
String length: 4
String value: key3
Integer value: 20
String length: 4
String value: key4
Boolean value: 1
String length: 4
String value: key5
Null value found
Good job!
```

The callback functions implemented by the Lexepa\_Srl\_Abstract class are contained and documented in the interface file [class-lexepa-srl-interface.php](https://github.com/lbreme/lexepa-srl/blob/main/src/class-lexepa-srl-interface.php)

The Lexepa\_Srl library was created by taking as reference the following document that specifies how an object is serialized in PHP:

[https://www.phpinternalsbook.com/php5/classes\_objects/serialization.html](https://www.phpinternalsbook.com/php5/classes_objects/serialization.html)

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Total

4

Last Release

1815d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

parserserializelexer

### Embed Badge

![Health badge](/badges/lbreme-lexepa-srl/health.svg)

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

###  Alternatives

[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k910.8M117](/packages/doctrine-lexer)[cerbero/json-parser

Zero-dependencies pull parser to read large JSON from any source in a memory-efficient way.

803474.6k5](/packages/cerbero-json-parser)[creof/geo-parser

Parser for geography coordinate strings

624.4M15](/packages/creof-geo-parser)[creof/wkt-parser

Parser for well-known text (WKT) object strings

554.8M16](/packages/creof-wkt-parser)[tmilos/lexer

Lexical analyzer with individual token definition with regular expressions

211.7M2](/packages/tmilos-lexer)[yosymfony/parser-utils

Parser utilities

201.5M2](/packages/yosymfony-parser-utils)

PHPackages © 2026

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