PHPackages                             cjstroud/classnames-php - 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. cjstroud/classnames-php

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

cjstroud/classnames-php
=======================

A simple PHP utility for conditionally joining classNames together

1.0.0(9y ago)20166.9k—4.5%11MITPHP

Since Apr 29Pushed 9y ago2 watchersCompare

[ Source](https://github.com/CJStroud/classnames-php)[ Packagist](https://packagist.org/packages/cjstroud/classnames-php)[ RSS](/packages/cjstroud-classnames-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

classnames-php
==============

[](#classnames-php)

[![Build Status](https://camo.githubusercontent.com/ddbe48aa4572c9f9787933eda9dc7de2d9baaf6a25b9ed8e6ccd2658e97f39fa/68747470733a2f2f7472617669732d63692e6f72672f434a5374726f75642f636c6173736e616d65732d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/CJStroud/classnames-php)

PHP port of the JavaScript classNames utility.

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

[](#installation)

```
composer require cjstroud/classnames-php

```

The classNames can be accessed anywhere.

```
classNames('foo', ['bar' => true]); // 'foo bar'

```

Usage
-----

[](#usage)

The `classNames` function takes any number of arguments which can be a string or array. When using an array, if the value associated with a given key is falsy, that key won't be included in the output. If no value is given the true is assumed.

```
classNames('foo'); // 'foo'
classNames(['foo' => true]); // 'foo'
classNames('foo', ['bar' => false, 'baz' => true]); // 'foo baz'
classNames(['foo', 'bar' => true]) // 'foo bar'

// Falsy values get ignored
classNames('foo', null, 0, false, 1); // 'foo 1'

```

Objects and functions will be ignored, unless the object has \_\_toString() function. If it does that will be called and the string value used.

```
class ExampleObject {
    function __toString()
    {
        return 'bar';
    }
}

classNames('foo', function() {}, new stdClass(), new ExampleObject()); // 'foo bar'

```

Laravel Blade
-------------

[](#laravel-blade)

```

```

License
-------

[](#license)

[MIT](LICENSE). Copyright (c) 2017 Chris Stroud.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3306d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bac071d5b9808487d3be47ceb20664b7256a78279bc60d2c2119e17e39f7412?d=identicon)[cstroud](/maintainers/cstroud)

---

Top Contributors

[![cstro](https://avatars.githubusercontent.com/u/4259409?v=4)](https://github.com/cstro "cstro (1 commits)")

---

Tags

classnameclassnames-phpcss-classeshelperhelper-functionsphputil

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cjstroud-classnames-php/health.svg)

```
[![Health](https://phpackages.com/badges/cjstroud-classnames-php/health.svg)](https://phpackages.com/packages/cjstroud-classnames-php)
```

PHPackages © 2026

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