PHPackages                             ajf/newtype - 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. ajf/newtype

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

ajf/newtype
===========

A handy function for creating opaque types

v1.0.3(8y ago)18231LGPL-3.0-or-laterPHPPHP &gt;=7.0.0

Since Nov 10Pushed 8y ago1 watchersCompare

[ Source](https://github.com/TazeTSchnitzel/newType)[ Packagist](https://packagist.org/packages/ajf/newtype)[ Docs](http://github.com/TazeTSchnitzel/newType)[ RSS](/packages/ajf-newtype/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (5)Used By (0)

newType - Create an opaque type with a single line of code
==========================================================

[](#newtype---create-an-opaque-type-with-a-single-line-of-code)

`newType()` is a handy function for creating opaque types, that is, a type that merely wraps another type. It takes two parameters: the name of your new wrapper type, and the name of the type you want to wrap. You get a class with a constructor taking a value of the wrapped type, and an `->unbox()` method to get out the value of the wrapped type.

Require it with `composer require ajf/newtype` to use it. It's PHP 7-only, since PHP 7 is the first version of PHP with scalar type declarations. It would be possible to backport this, though.

An example of where you might use this:

```
