PHPackages                             joomla/data - 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. [Framework](/categories/framework)
4. /
5. joomla/data

ActiveJoomla-package[Framework](/categories/framework)

joomla/data
===========

Joomla Data Package

4.0.0(9mo ago)6299.5k↓21.6%6[1 issues](https://github.com/joomla-framework/data/issues)1GPL-2.0-or-laterPHPPHP ^8.3.0CI passing

Since Jun 4Pushed 9mo ago12 watchersCompare

[ Source](https://github.com/joomla-framework/data)[ Packagist](https://packagist.org/packages/joomla/data)[ Docs](https://github.com/joomla-framework/data)[ RSS](/packages/joomla-data/feed)WikiDiscussions 3.x-dev Synced 1mo ago

READMEChangelog (6)Dependencies (6)Versions (21)Used By (1)

The Data Package [![Build Status](https://github.com/joomla-framework/data/actions/workflows/ci.yml/badge.svg?branch=3.x-dev)](https://github.com/joomla-framework/data)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#the-data-package-)

[![Latest Stable Version](https://camo.githubusercontent.com/2ae439ec7c5d9b2b7247e14f338d860ad54a6902a6bade3ec099e678e82fbc96/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f646174612f762f737461626c65)](https://packagist.org/packages/joomla/data)[![Total Downloads](https://camo.githubusercontent.com/60f833bec967db6c85ec370ba544c57c8633f20f36ada00a94eec1a9c4643110/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f646174612f646f776e6c6f616473)](https://packagist.org/packages/joomla/data)[![Latest Unstable Version](https://camo.githubusercontent.com/1a55e27817319a147b8462073aa7150d46f26284d26f093c3a179e4773a09f22/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f646174612f762f756e737461626c65)](https://packagist.org/packages/joomla/data)[![License](https://camo.githubusercontent.com/9e12bc94aed237d28fcdb21033c0714c20b10f5075c4741b8459896eba47a4fe/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f646174612f6c6963656e7365)](https://packagist.org/packages/joomla/data)

### `Data\DataObject`

[](#datadataobject)

`Data\DataObject` is a class that is used to store data but allowing you to access the data by mimicking the way PHP handles class properties. Rather than explicitly declaring properties in the class, `Data\DataObject` stores virtual properties of the class in a private internal array. Concrete properties can still be defined but these are separate from the data.

#### Construction

[](#construction)

The constructor for a new `Data\DataObject` object can optionally take an array or an object. The keys of the array or the properties of the object will be bound to the properties of the `Data\DataObject` object.

```
use Joomla\Data\DataObject;

// Create an empty object.
$object1 = new DataObject;

// Create an object with data. You can use an array or another object.
$data = array(
    'foo' => 'bar',
);

$object2 = new DataObject($data);

// The following should echo "bar".
echo $object2->foo;
```

#### General Usage

[](#general-usage)

`Data\DataObject` includes magic getters and setters to provide access to the internal property store as if they were explicitly declared properties of the class.

The `bind` method allows for injecting an existing array or object into the `Data\DataObject` object.

The `dump` method gets a plain `stdClass` version of the `Data\DataObject` object's properties. It will also support recursion to a specified number of levels where the default is 3 and a depth of 0 would return a `stdClass` object with all the properties in native form. Note that the `dump` method will only return virtual properties set binding and magic methods. It will not include any concrete properties defined in the class itself.

The `JsonSerializable` interface is implemented. This method proxies to the `dump` method (defaulting to a recursion depth of 3). Note that this interface only takes effect implicitly in PHP 5.4 so any code built for PHP 5.3 needs to explicitly use either the `jsonSerialize` or the `dump` method before passing to `json_encode`.

The `Data\DataObject` class also implements the `IteratorAggregate` interface so it can easily be used in a `foreach` statement.

```
use Joomla\Data\DataObject;

// Create an empty object.
$object = new DataObject;

// Set a property.
$object->foo = 'bar';

// Get a property.
$foo = $object->foo;

// Binding some new data to the object.
$object->bind(array('goo' => 'car');

// Get a plain object version of the data object.
$stdClass = $object->dump();

// Get a property with a default value if it is not already set.
$foo = $object->foo ?: 'The default';

// Iterate over the properties as if the object were a real array.
foreach ($object as $key => $value)
{
    echo "\n$key = $value";
}

if (version_compare(PHP_VERSION, '5.4') >= 0)
{
	// PHP 5.4 is aware of the JsonSerializable interface.
	$json = json_encode($object);
}
else
{
	// Have to do it the hard way to be compatible with PHP 5.3.
	$json = json_encode($object->jsonSerialize());
}
```

### `Data\DataSet`

[](#datadataset)

`Data\DataSet` is a collection class that allows the developer to operate on a list of `Data\DataObject` objects as if they were in a typical PHP array (`Data\DataSet` implements the `ArrayAccess`, `Countable` and `Iterator` interfaces).

#### Construction

[](#construction-1)

A typical `Data\DataSet` object will be instantiated by passing an array of `Data\DataObject` objects in the constructor.

```
use Joomla\Data\DataObject;
use Joomla\Data\DataSet;

// Create an empty object.
$players = new DataSet(
    array(
        new DataObject(array('race' => 'Elf', 'level' => 1)),
        new DataObject(array('race' => 'Chaos Dwarf', 'level' => 2)),
    )
);
```

#### General Usage

[](#general-usage-1)

Array elements can be manipulated with the `offsetSet` and `offsetUnset` methods, or by using PHP array nomenclature.

The magic `__get` method in the `Data\DataSet` class effectively works like a "get column" method. It will return an array of values of the properties for all the objects in the list.

The magic `__set` method is similar and works like a "set column" method. It will set all a value for a property for all the objects in the list.

The `clear` method will clear all the objects in the data set.

The `keys` method will return all of the keys of the objects stored in the set. It works like the `array_keys` function does on an PHP array.

```
use Joomla\Data\DataObject;

// Add a new element to the end of the list.
$players[] => new DataObject(array('race' => 'Skaven', 'level' => 2));

// Add a new element with an associative key.
$players['captain'] => new DataObject(array('race' => 'Human', 'level' => 3));

// Get a keyed element from the list.
$captain = $players['captain'];

// Set the value of a property for all objects. Upgrade all players to level 4.
$players->level = 4;

// Get the value of a property for all object and also the count (get the average level).
$average = $players->level / count($players);

// Clear all the objects.
$players->clear();
```

`Data\DataSet` supports magic methods that operate on all the objects in the list. Calling an arbitrary method will iterate of the list of objects, checking if each object has a callable method of the name of the method that was invoked. In such a case, the return values are assembled in an array forming the return value of the method invoked on the `Data\DataSet` object. The keys of the original objects are maintained in the result array.

```
use Joomla\Data\DataObject;
use Joomla\Data\DataSet;

/**
 * A custom data object.
 *
 * @since  1.0
 */
class PlayerObject extends DataObject
{
    /**
     * Get player damage.
     *
     * @return  integer  The amount of damage the player has received.
     *
     * @since   1.0
     */
    public function hurt()
    {
        return (int) $this->maxHealth - $this->actualHealth;
    }
}

$players = new DataSet(
    array(
        // Add a normal player.
        new PlayerObject(array('race' => 'Chaos Dwarf', 'level' => 2,
        	'maxHealth' => 40, 'actualHealth' => '32')),
        // Add an invincible player.
        new PlayerObject(array('race' => 'Elf', 'level' => 1)),
    )
);

// Get an array of the hurt players.
$hurt = $players->hurt();

if (!empty($hurt))
{
    // In this case, $hurt = array(0 => 8);
    // There is no entry for the second player
    // because that object does not have a "hurt" method.
    foreach ($hurt as $playerKey => $player)
    {
        // Do something with the hurt players.
    }
};
```

### `Data\DumpableInterface`

[](#datadumpableinterface)

`Data\DumpableInterface` is an interface that defines a `dump` method for dumping the properties of an object as a `stdClass` with or without recursion.

Installation via Composer
-------------------------

[](#installation-via-composer)

Add `"joomla/data": "~3.0"` to the require block in your composer.json and then run `composer install`.

```
{
	"require": {
		"joomla/data": "~3.0"
	}
}
```

Alternatively, you can simply run the following from the command line:

```
composer require joomla/data "~3.0"
```

If you want to include the test sources, use

```
composer require --prefer-source joomla/data "~3.0"
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance52

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 52.4% 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 ~277 days

Recently: every ~164 days

Total

17

Last Release

298d ago

Major Versions

1.2.0 → 2.0.0-beta2020-06-05

2.0.1 → 3.0.02023-10-06

3.0.3 → 4.0.02025-07-24

PHP version history (6 changes)1.0-alphaPHP &gt;=5.3.10

1.2.0PHP &gt;=5.3.10|&gt;=7.0

2.0.0-betaPHP ^7.2.5

2.0.1PHP ^7.2.5|~8.0.0|~8.1.0

3.0.0PHP ^8.1.0

4.0.0PHP ^8.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/305a2164440014dcef9ac681c139fe5e8a1ce1d7a8c3b3cfb828497729a4c70e?d=identicon)[wilsonge](/maintainers/wilsonge)

---

Top Contributors

[![mbabker](https://avatars.githubusercontent.com/u/368545?v=4)](https://github.com/mbabker "mbabker (86 commits)")[![Hackwar](https://avatars.githubusercontent.com/u/313866?v=4)](https://github.com/Hackwar "Hackwar (27 commits)")[![nibra](https://avatars.githubusercontent.com/u/827605?v=4)](https://github.com/nibra "nibra (8 commits)")[![dongilbert](https://avatars.githubusercontent.com/u/718028?v=4)](https://github.com/dongilbert "dongilbert (8 commits)")[![ianmacl](https://avatars.githubusercontent.com/u/176534?v=4)](https://github.com/ianmacl "ianmacl (5 commits)")[![richard67](https://avatars.githubusercontent.com/u/7413183?v=4)](https://github.com/richard67 "richard67 (5 commits)")[![heelc29](https://avatars.githubusercontent.com/u/66922325?v=4)](https://github.com/heelc29 "heelc29 (5 commits)")[![realityking](https://avatars.githubusercontent.com/u/628508?v=4)](https://github.com/realityking "realityking (3 commits)")[![wilsonge](https://avatars.githubusercontent.com/u/1986000?v=4)](https://github.com/wilsonge "wilsonge (3 commits)")[![joomla-jenkins](https://avatars.githubusercontent.com/u/929228?v=4)](https://github.com/joomla-jenkins "joomla-jenkins (2 commits)")[![Llewellynvdm](https://avatars.githubusercontent.com/u/5607939?v=4)](https://github.com/Llewellynvdm "Llewellynvdm (2 commits)")[![rdeutz](https://avatars.githubusercontent.com/u/467356?v=4)](https://github.com/rdeutz "rdeutz (2 commits)")[![zero-24](https://avatars.githubusercontent.com/u/2596554?v=4)](https://github.com/zero-24 "zero-24 (1 commits)")[![brianteeman](https://avatars.githubusercontent.com/u/1296369?v=4)](https://github.com/brianteeman "brianteeman (1 commits)")[![eddieajau](https://avatars.githubusercontent.com/u/700871?v=4)](https://github.com/eddieajau "eddieajau (1 commits)")[![HLeithner](https://avatars.githubusercontent.com/u/1497730?v=4)](https://github.com/HLeithner "HLeithner (1 commits)")[![jbanety](https://avatars.githubusercontent.com/u/1055330?v=4)](https://github.com/jbanety "jbanety (1 commits)")[![PhilETaylor](https://avatars.githubusercontent.com/u/400092?v=4)](https://github.com/PhilETaylor "PhilETaylor (1 commits)")[![RobertDeutz](https://avatars.githubusercontent.com/u/43096773?v=4)](https://github.com/RobertDeutz "RobertDeutz (1 commits)")[![Achal-Aggarwal](https://avatars.githubusercontent.com/u/3330262?v=4)](https://github.com/Achal-Aggarwal "Achal-Aggarwal (1 commits)")

---

Tags

data-objectjoomlajoomla-frameworkphpframeworkdatajoomla

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/joomla-data/health.svg)

```
[![Health](https://phpackages.com/badges/joomla-data/health.svg)](https://phpackages.com/packages/joomla-data)
```

###  Alternatives

[joomla/application

Joomla Application Package

23404.8k11](/packages/joomla-application)[joomla/github

Joomla Github Package

2863.3k2](/packages/joomla-github)[joomla/registry

Joomla Registry Package

16468.6k20](/packages/joomla-registry)[joomla/filesystem

Joomla Filesystem Package

12369.7k7](/packages/joomla-filesystem)[joomla/oauth2

Joomla OAuth2 Package

10303.1k2](/packages/joomla-oauth2)[isolate/isolate

Isolate is an abstraction layer for data persistence. Operations related to tracking changes and saving data are done in transactions which makes your code not aware of sotrage type.

314.1k5](/packages/isolate-isolate)

PHPackages © 2026

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