PHPackages                             sajjad-razeqi/cobject - 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. sajjad-razeqi/cobject

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

sajjad-razeqi/cobject
=====================

cObject is a stdclass replacement class for callable objects and normal objects

1.0.2(4mo ago)131[1 PRs](https://github.com/Sajjad-Razeqi/cObject/pulls)MITPHP

Since Jan 31Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/Sajjad-Razeqi/cObject)[ Packagist](https://packagist.org/packages/sajjad-razeqi/cobject)[ RSS](/packages/sajjad-razeqi-cobject/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (5)Used By (0)

cObject - Callable Object for PHP
=================================

[](#cobject---callable-object-for-php)

[![cObject Logo](./imgs/logo.webp)](./imgs/logo.webp)

**cObject** is an enhanced alternative to `stdClass` in PHP, providing additional functionality, including callable properties and seamless array-object conversion.

Features
--------

[](#features)

- **Extended `stdClass` functionality** – more powerful and flexible.
- **Callable properties** – define properties that behave like functions.
- **Direct array-to-object conversion** – easily transform arrays into objects.
- **Effortless object-to-array conversion** – switch between formats with ease.
- **Array-like object access** – interact with objects just like arrays.

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

[](#installation)

You can install `cObject` via Composer:

```
composer require sajjad-razeqi/cobject
```

cObject Documentation
---------------------

[](#cobject-documentation)

### Usage cObject:

[](#usage-cobject)

#### Like stdClass:

[](#like-stdclass)

You can use it just like `stdClass`.

```
use cObject\cObject;

$cObject = new cObject();

// Define:
$cObject->data1 = "Hello, ";
$cObject->data2 = function(string $name){
    echo "You're Welcome $name!";
};

// Usage:
echo $cObject->data1;
$cObject->data2("Sajjad");

// Unset:
unset($cObject->data1, $cObject->data2);
```

#### Convert an array to a cObject:

[](#convert-an-array-to-a-cobject)

You can directly convert your array into a `cObject`.

```
use cObject\cObject;

// Define:
$cObject = new cObject([
    "data1" => "Hello, ",
    "data2" => function(string $name){
        echo "You're Welcome $name!";
    }
]);

// Usage:
echo $cObject->data1;
$cObject->data2("Sajjad");

// Unset:
unset($cObject->data1, $cObject->data2);
```

**Please note:** Only associative arrays can be converted to cObject. Otherwise, the array will remain unchanged in the `cObject`.

##### E.g.

[](#eg)

```
use cObject\cObject;

// Define:
$cObject = new cObject([
    "array" => [
        "data1",
        "data2",
        "data3",
        "data4",
    ]
]);

// Usage:
echo $cObject->array[0];

// Unset:
unset($cObject->array[3]);

// Check:
var_dump(is_iterable($cObject->array)); // bool(true)
var_dump(is_array($cObject->array)); // bool(true)
```

#### Like Arrays:

[](#like-arrays)

You can use it just like `Arrays`.

```
use cObject\cObject;

$cObject = new cObject();

// Define:
$cObject["data1"] = "Hello, ";
$cObject["data2"] = function(string $name){
    echo "You're Welcome $name!";
};

// Usage:
echo $cObject["data1"];
$cObject["data2"]("Sajjad");

// Unset:
unset($cObject["data1"], $cObject["data2"]);

// Check:
var_dump(is_iterable($cObject)); // bool(false)
var_dump(is_array($cObject)); // bool(false)
```

**Warning**: This only simulates an array but is not `iterable`.

#### Usage combination:

[](#usage-combination)

```
use cObject\cObject;

// Define:
$cObject = new cObject([
    "data1" => "Hello, ",
    "data2" => function(string $name){
        echo "hi $name!";
    }
]);
$cObject->data1 = "Ok, ";

// Usage:
echo $cObject->data1;
$cObject["data2"]("Sajjad");

// Unset:
unset($cObject["data1"], $cObject->data2);
```

### More options:

[](#more-options)

#### String casting:

[](#string-casting)

When using string casting, the cObject will convert it to JSON.

```
use cObject\cObject;

$cObject = new cObject([
    "data1" => "Hello, ",
    "data2" => function(string $name){
        echo "You're Welcome $name!";
    }
]);

// ======================
echo $cObject; // { "_": "cObject", "data1": "Hello", "data2": {} }

// Or:
$string = (string) $cObject; // { "_": "cObject", "data1": "Hello", "data2": {} }
```

**Please note:** If you use string casting, any callable properties cannot be converted to a string. Additionally, after decoding the JSON string, the callable properties will be lost.

#### Convert the cObject to an array:

[](#convert-the-cobject-to-an-array)

```
use cObject\cObject;

$cObject = new cObject([
    "data1" => "Hello",
    "data2" => function(string $name){
        echo "You're Welcome $name!";
    }
]);

// ======================
$cObject->MycObjectToArray(); // return an array

// Or:
$TheArray = cObject::cObjectToArray($cObject); // return an array

// Check:
var_dump(is_iterable($TheArray)); // bool(true)
var_dump(is_array($TheArray)); // bool(true)
```

**Note:** This method converts an object into a real array.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance75

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

###  Release Activity

Cadence

Every ~112 days

Total

4

Last Release

133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c07c9f3db6ec49e906eef7c182a545e26fbdbba2f1c30f5c22be95a5b98c96b5?d=identicon)[Sajjad-Razeqi](/maintainers/Sajjad-Razeqi)

---

Top Contributors

[![Sajjad-Razeqi](https://avatars.githubusercontent.com/u/157571149?v=4)](https://github.com/Sajjad-Razeqi "Sajjad-Razeqi (9 commits)")

### Embed Badge

![Health badge](/badges/sajjad-razeqi-cobject/health.svg)

```
[![Health](https://phpackages.com/badges/sajjad-razeqi-cobject/health.svg)](https://phpackages.com/packages/sajjad-razeqi-cobject)
```

###  Alternatives

[felixnagel/t3extblog

A record based blog extension for TYPO3 CMS. Easy to use and packed with features (incl. comments, subscriptions for comments and posts, Wordpress like subscription manager, reasonable email sending in FE and BE, GDPR ready, BE modules, Dashboard widgets, RSS, Sitemap, ...). Flexible and powerful!

3421.6k](/packages/felixnagel-t3extblog)

PHPackages © 2026

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