PHPackages                             starship/scalar - 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. starship/scalar

ActiveLibrary

starship/scalar
===============

Scalar Objects for php5.3

07PHP

Since Feb 8Pushed 13y ago2 watchersCompare

[ Source](https://github.com/evan108108/Scalar)[ Packagist](https://packagist.org/packages/starship/scalar)[ RSS](/packages/starship-scalar/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Starship/Scalar
===============

[](#starshipscalar)

Provides Scalar Objects in PHP\* thus helping improve PHP's inconstant API. The best part is that you can use any of PHP's built in string / array functions!

\*Currently Scalar supports strings and arrays but future versions will support integers and floats.
\*This library requires PHP 5.3 or greater.

Install
-------

[](#install)

The recommended way to install react/scalar is [through composer](http://getcomposer.org).

```
{
    "require": {
        "starship/scalar": "dev-master"
    }
}
```

Examples
--------

[](#examples)

\###Simple String Operations
You may use any php string method. Here are a few examples:

```
require __DIR__.'/vendor/autoload.php';

$my_string = new Starship\Scalar\Str('This is a great string!');

echo $my_string; //Outputs: 'This is a great string!'
echo $my_string->strlen(); //Outputs: 23
echo $my_string->strpos('great'); //Outputs: 10
echo $my_string; //Outputs: 'This is a great string!'
```

\###Simple Array Operations

You may use any php array method. Here are a few examples:

```
require __DIR__.'/vendor/autoload.php';

$my_array = new Starship\Scalar\sArray(array(1,2,3,4));

echo $my_array; //Outputs: '[1,2,3,4]'
echo $my_array[0]; //Outputs: 1
echo $my_array[1]; //Outputs: 2
echo $my_array->count(); //Outputs: 4
echo $my_array->implode('_'); //Outputs: '1_2_3_4'
$new_array = $my_array->array_unshift(10);
echo $new_array; //Outputs: '[10,1,2,3,4]'
echo $new_array[0] //Outputs: 10
```

By default Scalar maps you're string/array to the first param of the PHP function your executing. This as you know is not sufficient, luckily Scalar provides two methods for resolving this. The first is by using a token and the second is using a class called MethodMapper. Lets take a looka at the token replacement method:

```
require __DIR__.'/vendor/autoload.php';

$my_string = new Starship\Scalar\Str('This is a great string!');
$my_array = new Starship\Scalar\sArray(array(1,2,3,4));

echo $my_string; //Outputs: 'This is a great string!'

//We use the token '___' which will be replaced by the value of $my_string ('This is a great string!')

echo $my_string->str_replace('great', 'good', '___'); //Outputs: 'This is a good string!'

echo $my_array->implode('|', '___'); //Outputs: '1|2|3|4'
```

Using the token replacement can be a little less then ideal. Thats where MethodMapper comes in. MethodMapper allows you to create mappings for the PHP functions you use a lot. Lets take a quick look at the MethodMapper class and then see an example of it works.

```
namespace Starship\Scalar;

class MethodMapper
{
	public static $method_map = array(
		"str_replace" => array('haystack'=>3),
		"explode" => array('haystack'=>2),
		"implode" => array('haystack'=>2),
	);
}
```

In the above example we see that the MethodMapper class consists of a single static variable $method\_map. $method\_map is a simple associative array. Each item in $method\_map is keyed with the PHP method name and contains an associative array that tells Scalar the position of the haystack (your string/array value). You can see that str\_replace is mapped so that the haystack will be passed to the third paramater making the example below possible and eliminating the need for the token:

```
require __DIR__.'/vendor/autoload.php';

$my_string = new Starship\Scalar\Str('This is a great string!');

echo $my_string; //Outputs: 'This is a great string!'
echo $my_string->str_replace('great', 'super great'); //Outputs: 'This is a super great string!'
```

### Output Channing

[](#output-channing)

Scalar allows you to chain or pipe the output of one or more methods into the next. To do this all you have to do is add the invoke "()" to your var:

```
require __DIR__.'/vendor/autoload.php';

$my_string = new Starship\Scalar\Str('This is a great string!');

echo $my_string; //Outputs: 'This is a great string!'
echo $my_string()->str_replace('great', 'super great')->strlen(); //Outputs: 29
echo $my_string()->str_replace('great', 'super great')->substr(0,10)->strlen(); //Outputs 10;
echo $my_string()->explode('great')->count(); //Outputs: 2
echo $my_string()->explode('great')->implode('wow'); //Outputs: 'This is a wow string!'

$my_array = new Starship\Scalar\sArray(array(1,2,3,4));

echo $my_array()->implode('')->strlen(); //Outputs: 4
echo $my_array()->implode('')->strlen()->rand(10); //Outputs: random number between 4 and 10
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/801e92d75e08f2a39f32c6c3b40cd8f6e71c0ddc145812bb389b0359dc832be8?d=identicon)[evan108108](/maintainers/evan108108)

---

Top Contributors

[![evan108108](https://avatars.githubusercontent.com/u/197995?v=4)](https://github.com/evan108108 "evan108108 (7 commits)")

### Embed Badge

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

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

PHPackages © 2026

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