PHPackages                             xethron/to-string - 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. xethron/to-string

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

xethron/to-string
=================

Converts Variables to strings (like print\_r) with limiting functions, and Exceptions to strings without cutting off important information.

1.0.2(12y ago)419.2k1GPL v3PHPPHP &gt;=5.0.0

Since Feb 1Pushed 12y ago2 watchersCompare

[ Source](https://github.com/Xethron/to-string)[ Packagist](https://packagist.org/packages/xethron/to-string)[ Docs](http://github.com/Xethron/to-string)[ RSS](/packages/xethron-to-string/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (1)

ToString
========

[](#tostring)

[![Latest Stable Version](https://camo.githubusercontent.com/577bc2a2e8c999170ce70a28b3c1873d98ea19f0dd81ada92a23f9646e7f07c1/68747470733a2f2f706f7365722e707567782e6f72672f78657468726f6e2f746f2d737472696e672f762f737461626c652e706e67)](https://packagist.org/packages/xethron/to-string) [![Total Downloads](https://camo.githubusercontent.com/5a291c8840dedeb4679d6f5b871c086d198485f617cfa8fece51823b80b8b532/68747470733a2f2f706f7365722e707567782e6f72672f78657468726f6e2f746f2d737472696e672f646f776e6c6f6164732e706e67)](https://packagist.org/packages/xethron/to-string) [![Latest Unstable Version](https://camo.githubusercontent.com/ffef0560f2149fc651de640875dab89f5d72ed91abf7eb27c828ef1f0605b6b9/68747470733a2f2f706f7365722e707567782e6f72672f78657468726f6e2f746f2d737472696e672f762f756e737461626c652e706e67)](https://packagist.org/packages/xethron/to-string) [![License](https://camo.githubusercontent.com/08247427adc5060972dbdb305da8f9248d28049cb1a43d55996b750e2ad06a5e/68747470733a2f2f706f7365722e707567782e6f72672f78657468726f6e2f746f2d737472696e672f6c6963656e73652e706e67)](https://packagist.org/packages/xethron/to-string)

Logging variables can sometimes cause huge logs, especially if you want to email those logs to yourself.

On the other hand, logging exceptions with the default \_\_toString can will most likely give you just enough information to confuse the hell out of you!

Variable to String
==================

[](#variable-to-string)

This is a function that will display a variable similar to print\_r, with the ability to specify the max\_lines, max\_depth (for arrays) and min\_depth (for arrays).

This means that you will never get an email with an array 3000 lines long as you would with print\_r.

`Xethron\ToString::variable( $var, $max_lines, $max_depth, $min_depth )`

I recommend adding a global function to one of your startup files for easier access:

```
function varToStr( $var, $max_lines = 10, $max_depth = 4, $min_depth = 2 )
{
    return Xethron\ToString::variable( $var, $max_lines, $max_depth, $min_depth );
}
```

Exception to String
===================

[](#exception-to-string)

This converts an Exception to string, much like PHP's \_\_toString, however, it won't cut off those important pieces of information you require while debugging.

On top of that, it also uses the Variable to String to to include all the variables passed in the Stack Trace.

Two functions are available:
----------------------------

[](#two-functions-are-available)

`Xethron\ToString::exception( $e ); // This will print out the entire Exception`

`Xethron\ToString::trace( $e->getTrace() ); // This will only print out the stack trace`

License
=======

[](#license)

ToString is distributed under the terms of the GNU General Public License, version 3 or later.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

4467d ago

### Community

Maintainers

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

---

Top Contributors

[![Xethron](https://avatars.githubusercontent.com/u/1497338?v=4)](https://github.com/Xethron "Xethron (5 commits)")

---

Tags

convertstringprint\_r

### Embed Badge

![Health badge](/badges/xethron-to-string/health.svg)

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

###  Alternatives

[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)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4235.0M21](/packages/kwn-number-to-words)[opis/string

Multibyte strings as objects

7420.9M7](/packages/opis-string)

PHPackages © 2026

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