PHPackages                             phpgt/propfunc - 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. phpgt/propfunc

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

phpgt/propfunc
==============

Property accessor and mutator functions.

v1.0.1(5y ago)12.9M—5.6%[3 PRs](https://github.com/PhpGt/PropFunc/pulls)3MITPHPPHP &gt;=8.0CI passing

Since Feb 17Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/PhpGt/PropFunc)[ Packagist](https://packagist.org/packages/phpgt/propfunc)[ GitHub Sponsors](https://github.com/sponsors/PhpGt)[ RSS](/packages/phpgt-propfunc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (13)Used By (3)

Property accessor and mutator functions.
========================================

[](#property-accessor-and-mutator-functions)

Property accessors and mutators are commonly referred to as "getter" and "setter" functions. This library uses [PHP's Magic Methods](https://www.php.net/manual/en/language.oop5.magic.php) to easily hook up getter and setter functions that are exposed externally as normal properties, via the `MagicProp` trait.

Why? This kind of functionality can certainly be seen as a hack, but sometimes hacks are necessary. Specifically PHP.Gt is implementing [the DOM standard in PHP](https://www.php.gt/dom) which requires certain properties to have "live" or "readonly" functionality, which is only possible using magic \_\_get and \_\_set functions. This library simply holds the reusable behaviour for other repositories that require it.

---

[ ![Build status](https://camo.githubusercontent.com/3fc020e8d87f71dd7254485b3c61c280c5f268d0e700b519feadbd313e1a184a/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f7066756e632d6275696c642e737667)](https://github.com/PhpGt/PropFunc/actions)[ ![Code quality](https://camo.githubusercontent.com/11fd0d1063719c3cb6e1a84b2ace26824bbbfee70fbbe66f0255c3eb7616a385/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f7066756e632d7175616c6974792e737667)](https://scrutinizer-ci.com/g/PhpGt/PropFunc)[ ![Code coverage](https://camo.githubusercontent.com/0db49176c9d60ec627d9be63e9f3616e71748249a722b28d72902c9141d6972b/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f7066756e632d636f7665726167652e737667)](https://scrutinizer-ci.com/g/PhpGt/PropFunc)[ ![Current version](https://camo.githubusercontent.com/05c65dd00546e99f0b8f97a57505860487eac819225d427226b75d54025c6e7b/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f7066756e632d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/PropFunc)[ ![PHP.Gt/PropFunc documentation](https://camo.githubusercontent.com/5a1fd230a982f5ce5011c62f1f5db86e5d4e7b6dbae89829a85ba52c6de83236/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f7066756e632d646f63732e737667)](http://www.php.gt/propfunc)Example usage: Read-only properties that are calculated upon access
-------------------------------------------------------------------

[](#example-usage-read-only-properties-that-are-calculated-upon-access)

See the class `Day` below, which represents a day in time:

```
use Gt\PropFunc\MagicProp;

/**
 * @property-read bool $future True if the day is in the future
 * @property-read int $daysApart Days between now and this day
 */
class Day {
	use MagicProp;

	public function __construct(
		private DateTimeInterface $dateTime
	) {}

// Expose the "dateTime" private property with read-only access:
	private function __prop_get_dateTime():DateTimeInterface {
		return $this->dateTime;
	}

// Expose the "future" calculated property with read-only access:
	private function __prop_get_future():bool {
		$now = new DateTime();
		return $now < $this->dateTime;
	}

// Expose the "daysApart" calculated property with read-only access:
	private function __prop_get_daysApart():int {
		$now = new DateTime();
		$diff = $now->diff($this->dateTime);
		return $diff->days;
	}
}
```

See the code below which uses the `Day` class. It can access the properties, but not mutate them.

```
$day = new Day($dateTime);
echo "Day is $day->diff days in the ";
echo $day->future ? "future" : "past";
echo PHP_EOL;
$day->diff = 10;
echo "Exception thrown on line above!";
```

Usages
------

[](#usages)

- Read only properties - as with the above example, properties can be made read-only. This feature is [coming to the PHP language](https://wiki.php.net/rfc/write_once_properties), but without the ability to define the accessor logic.
- Live properties - if a property's value is required to update depending on certain conditions, a getter function is required.
- Property validation - if a property's value can't simply be validated by its type alone, the setter function can be used to ensure the value meets validation criteria.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance58

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity65

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

Every ~11 days

Total

4

Last Release

1882d ago

Major Versions

v0.1.0 → v1.0.02021-03-23

PHP version history (2 changes)v0.0.1PHP &gt;=7.4

v1.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgt-propfunc/health.svg)

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

###  Alternatives

[joanhey/adapterman

Use any framework and application with Workerman.

85255.9k1](/packages/joanhey-adapterman)[kunstmaan/seo-bundle

Annotating content with metadata for social sharing and seo purposes cannot be overlooked nowadays. The KunstmaanSeoBundle contains default editing functionality for OpenGraph data, meta descriptions, keywords and titles and Metriweb tags. Because the metatagging and tracking options are always changing, a free field to add custom header information is provided as well.

24130.0k2](/packages/kunstmaan-seo-bundle)

PHPackages © 2026

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