This package is abandoned and no longer maintained. The author suggests using the norse-blue/scalar-objects package instead.

PHP Primitive Objects

0.2.0 2019-05-26 16:14 UTC

This package is auto-updated.

Last update: 2022-02-01 13:16:33 UTC


Build Status PHP Version Stable Release 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35313139356563336134376138623037313338312f6d61696e7461696e6162696c697479 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35313139356563336134376138623037313338312f746573745f636f766572616765 Total Downloads GitHub

DEPRECATED: This package was growing too big and has now been deprecated in favor of the following smaller, segmented and more contained packages:

PHP Prim is a PHP library that exposes primitive types as immutable objects with convenience methods to operate on them.



Install Prim using Composer:

composer require norse-blue/prim


There are three ways to create a primitive object instance:

  1. Using the new keyword:

    use NorseBlue\Prim\Scalars\StringObject as Str;
    $str = new Str('my string');
    echo $str->upper();
    // Outputs:
    // MY STRING
  2. Using the facades:

    Note: params passed by reference are not supported in facades because the calls depend on __callStatic, which does not pass params by reference. See Overloading.

    use NorseBlue\Prim\Facades\Scalar\StringFacade as Str;
    echo Str::upper('my string');
    // Outputs:
    // MY STRING
  3. Using the namespaced functions:

    use NorseBlue\Prim\string;
    $str = string('my string');
    echo $str->upper();
    // Outputs:
    // MY STRING

You can also chain methods together:

use NorseBlue\Prim\string;

$str = string('THIS IS MY TEXT.')->lower()->ucfirst();
echo $str;

// Outputs:
// This is my text.

You don't need to worry about side-effects for scalar objects, as they are implemented as immutable objects and each method returns a new object. To store the value don't forget to assign it to a variable or it will be lost.


For the full documentation refer to the docs folder.


Please refer to the file for more information about what has changed recently.


Contributions to this project are accepted and encouraged. Please read the file for details on contributions.



If you discover any security related issues, please email instead of using the issue tracker.

Support the development

Do you like this project? Support it by donating

Buy me a coffee


PHP Prim is open-sourced software licensed under the MIT license.