PHPackages                             grottopress/nouveau - 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. grottopress/nouveau

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

grottopress/nouveau
===================

Instantiate a class by calling `::new()`, as an alternative to the `new` keyword.

00PHP

Since Feb 26Pushed 6y ago1 watchersCompare

[ Source](https://github.com/GrottoPress/nouveau)[ Packagist](https://packagist.org/packages/grottopress/nouveau)[ RSS](/packages/grottopress-nouveau/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

Nouveau
=======

[](#nouveau)

Description
-----------

[](#description)

*Nouveau* adds a `new()` static method to your class for constructing an instance of the class, as an alternative to using the `new` keyword.

In [ruby](https://ruby-lang.org) and [crystal](https://crystal-lang.org), you instantiate a class by doing:

```
MyClass.new(*args)
```

In [rust](https://rust-lang.org), it is idiomatic to add a *constructor* to a type:

```
pub struct MyStruct {}

impl MyStruct {
    pub fn new() {}
}
```

...and call it thus:

```
MyStruct::new();
```

*Nouveau* brings the same concept to PHP, allowing to intantiate a class thus:

```
MyClass::new(..$args);
```

The above is equivalent to:

```
new MyClass(...$args);
```

Among other things, this allows chaining a method immediately unto the constructed object.

This:

```
Person::new('John', 'Doe')->fullName();
```

Versus:

```
$john = new Person('John', 'Doe');
$john->fullName();

// OR
(new Person('John', 'Doe'))->fullName();
```

Usage
-----

[](#usage)

Install via composer:

`composer require grottopress/nouveau`

1. Import trait into your class:

```
