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

Abandoned → [chroma-x/stack-util](/?search=chroma-x%2Fstack-util)Library[Utility &amp; Helpers](/categories/utility)

markenwerk/stack-util
=====================

A PHP library providing common stack implementation.

1.1.0(1y ago)02.7k1MITPHPPHP &gt;=5.3

Since Jul 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/chroma-x/php-stack-util)[ Packagist](https://packagist.org/packages/markenwerk/stack-util)[ Docs](https://chroma-x.de/)[ RSS](/packages/markenwerk-stack-util/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (9)Dependencies (2)Versions (10)Used By (0)

PHP Stack Util
==============

[](#php-stack-util)

[![Build Status](https://camo.githubusercontent.com/c72d486ff143d0dbbc9984a44acadc91b942b0eb98deb64b15023f1da041bba3/68747470733a2f2f7472617669732d63692e6f72672f6368726f6d612d782f7068702d737461636b2d7574696c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chroma-x/php-stack-util)[![Test Coverage](https://camo.githubusercontent.com/e42794b2ce5421837b06331654482e60372a6fb74a5b7615049c910424ba8294/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368726f6d612d782f7068702d737461636b2d7574696c2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/chroma-x/php-stack-util/coverage)[![Dependency Status](https://camo.githubusercontent.com/4cd011e33523ca3d906ab3eb0e9837d4a6d90adb6f0ce330d07c436fbb59b0fe/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537376436326163393161616235303032376336636134642f62616467652e737667)](https://www.versioneye.com/user/projects/577d62ac91aab50027c6ca4d)[![SensioLabs Insight](https://camo.githubusercontent.com/60415508e378c2ca2063a1136d9d11abd4544f60424f5413f511f16c7b2e4a39/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f37303332323433332d653830312d343165332d626664312d6336626431333438346664662e737667)](https://insight.sensiolabs.com/projects/70322433-e801-41e3-bfd1-c6bd13484fdf)[![Code Climate](https://camo.githubusercontent.com/7a0afebd1dc3bd5dca25a70653407047c4c3fba0455b13fcda821d2e2acc566e/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368726f6d612d782f7068702d737461636b2d7574696c2f6261646765732f6770612e737667)](https://codeclimate.com/github/chroma-x/php-stack-util)[![Latest Stable Version](https://camo.githubusercontent.com/ecfe455c05ff3386c1f55ceebb3a7796b930c59fa5823c7e211708b42426a96e/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f737461636b2d7574696c2f762f737461626c65)](https://packagist.org/packages/chroma-x/stack-util)[![Total Downloads](https://camo.githubusercontent.com/fb5aaa3b61de9ecc2103e5c2aed9eb3619a092a0c40181a31f31a1ae86b4b507/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f737461636b2d7574696c2f646f776e6c6f616473)](https://packagist.org/packages/chroma-x/stack-util)[![License](https://camo.githubusercontent.com/2443644f8151046a70a824b22f76b8aa7bbd8b0dd1c4a2e00fdbf75faa31026f/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f737461636b2d7574696c2f6c6963656e7365)](https://packagist.org/packages/chroma-x/stack-util)

A PHP library providing common Stack implementation.

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

[](#installation)

```
{
   	"require": {
        "chroma-x/stack-util": "~1.0"
    }
}

```

Usage
-----

[](#usage)

### Autoloading and namesapce

[](#autoloading-and-namesapce)

```
require_once('path/to/vendor/autoload.php');

```

### Handling a stack

[](#handling-a-stack)

#### Pushing to the stack

[](#pushing-to-the-stack)

```
use ChromaX\StackUtil\Stack;

$stack = new Stack();

$stack
	->push('Item')
	->push('Another item')
	->push(12)
	->push(null)
	->push(8.12);

$stackSize = $stack->size();
echo 'Stack size: ' . $stackSize . PHP_EOL;

```

##### Output

[](#output)

```
Stack size: 5

```

### Reading from the stack

[](#reading-from-the-stack)

#### Getting the last item

[](#getting-the-last-item)

```
$lastItem = $stack->get();
echo 'Last item: ' . $lastItem . PHP_EOL;

```

##### Output

[](#output-1)

```
Last item: 8.12

```

#### Getting an item by index

[](#getting-an-item-by-index)

If the index is not available `null` is returned

```
$secondItem = $stack->get(1);
echo 'Second item: ' . $secondItem . PHP_EOL;

```

##### Output

[](#output-2)

```
Second item: Another item

```

### Popping from the stack

[](#popping-from-the-stack)

```
$poppedItem = $stack->pop();
echo 'Popped item: ' . $poppedItem . PHP_EOL;

$stackSize = $stack->size();
echo 'Stack size: ' . $stackSize . PHP_EOL;

```

##### Output

[](#output-3)

```
Popped item: 8.12
Stack size: 4

```

### Updating stacked values

[](#updating-stacked-values)

#### Updating the last item

[](#updating-the-last-item)

```
$lastItem = $stack
	->set('9.12')
	->get();
echo 'Updated last item: ' . $lastItem . PHP_EOL;

```

##### Output

[](#output-4)

```
Updated last item: 9.12

```

#### Updating an item by index

[](#updating-an-item-by-index)

```
$thirdItem = $stack
	->set('Third item', 2)
	->get(2);
echo 'Updated third item: ' . $thirdItem . PHP_EOL;

```

##### Output

[](#output-5)

```
Updated third item: Third item

```

### Removing from the stack

[](#removing-from-the-stack)

```
echo 'Stack size: ' . $stack->size() . PHP_EOL;
$stack->delete(1);
echo 'Stack size: ' . $stack->size() . PHP_EOL;

```

##### Output

[](#output-6)

```
Stack size: 4
Stack size: 3

```

### Iterating over the stack

[](#iterating-over-the-stack)

#### Using `foreach`

[](#using-foreach)

```
foreach ($stack as $stackItemKey => $stackItemValue) {
	echo 'Stack item ' . $stackItemKey . ': ' . $stackItemValue . PHP_EOL;
}

```

##### Output

[](#output-7)

```
Stack item 0: Item
Stack item 1: Third item
Stack item 2: 9.12

```

#### Using `for`

[](#using-for)

```
for ($i = 0, $n = $stack->size(); $i < $n; $i++) {
	echo 'Stack index ' . $i . ': ' . $stack->get($i) . PHP_EOL;
}

```

##### Output

[](#output-8)

```
Stack index 0: Item
Stack index 1: Third item
Stack index 2: 9.12

```

---

Contribution
------------

[](#contribution)

Contributing to our projects is always very appreciated.
**But: please follow the contribution guidelines written down in the [CONTRIBUTING.md](https://github.com/chroma-x/php-stack-util/blob/master/CONTRIBUTING.md) document.**

License
-------

[](#license)

PHP Stack Util is under the MIT license.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~382 days

Recently: every ~762 days

Total

9

Last Release

545d ago

Major Versions

0.0.1 → 1.0.02016-07-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5921241?v=4)[Martin Brecht-Precht](/maintainers/bonscho)[@Bonscho](https://github.com/Bonscho)

---

Top Contributors

[![abmarkenwerk](https://avatars.githubusercontent.com/u/61745221?v=4)](https://github.com/abmarkenwerk "abmarkenwerk (1 commits)")[![Bonscho](https://avatars.githubusercontent.com/u/5921241?v=4)](https://github.com/Bonscho "Bonscho (1 commits)")

---

Tags

commoncomposer-packagephp-librarystackstack

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aldemeery/onion

A layering mechanism for PHP applications.

5810.7k2](/packages/aldemeery-onion)

PHPackages © 2026

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