
Intercept every property read and write.
Validate, normalize and audit property access without adding getters, setters or magic methods. Attach behaviors directly to properties while keeping your code readable and statically analyzable.
Behaviors attached to properties, not setters
Mark a property with an attribute, and its reads and writes automatically trigger the behaviors you define.
Almost* any property
Validate, normalize or audit public, protected, private, promoted and final properties, with asymmetric visibility intact.
See what is coveredHow it works
The marked properties come back on the class PHP loads as native PHP 8.4 get and set hooks that run the behavior.
Follow one classAudit trail
Mark properties with #[Auditable] and record every change with the old and the new value, wherever the write comes from.
See the behavior
What you can intercept
Reads and writes of the properties you declare run through a behavior: validate, normalize or audit them. On a write, proceed() returns the value that is stored, so a behavior around the write can change it before it lands.
- Public, protected and private properties declared in the class
- Constructor-promoted and final properties: the constructor’s assignment is a write
- Public and protected properties inherited from a parent class
- Asymmetric visibility (private(set)) and attributes stay intact
- Array properties keep working with array_push(), through &get hooks
- Not supported: *Static, readonly and already-hooked properties are left alone: PHP allows no hooks on them.
#[Around('access(public App\Entity\User->email)')]public function normalizeEmail(FieldAccess $access): mixed{ if ($access->getAccessType() === FieldAccessType::Write) { return strtolower($access->proceed()); } return $access->proceed();}Native PHP hooks. Generated automatically.
The framework transforms your class into ordinary PHP files. Marked properties are rewritten with native PHP 8.4+ get and set hooks, which invoke the attached behaviors whenever the property is accessed.
Your class
Two properties carry #[Auditable], the attribute the audit behavior below looks for; the third doesn’t. The file stays exactly as you wrote it.
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Attribute\Auditable;
class Customer
{
#[Auditable]
public string $email = '';
#[Auditable]
public string $plan = 'free';
public string $displayName = '';
public function upgrade(string $plan): void
{
$this->plan = $plan;
}
}
Woven source
Your class body as the trait CustomerOriginalTrait. Each marked property leaves a one-line note, and every other line keeps its number for Xdebug.
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Attribute\Auditable;
trait CustomerOriginalTrait
was: class Customer
{
/* Moved by weaving interceptor to the {@see App\Entity\Customer->email} */
/* Moved by weaving interceptor to the {@see App\Entity\Customer->plan} */
public string $displayName = '';
public function upgrade(string $plan): void
{
$this->plan = $plan;
}
}
include_once AOP_CACHE_DIR . '/src/Entity/Customer.php';
Proxy class with hooks
The class PHP loads: your class name, the trait, and the marked properties declared again with their attribute, type and default, plus get and set hooks. Each hook passes the access through the audit middleware.
<?php
declare(strict_types=1);
namespace App\Entity;
use Go\Aop\Framework\InterceptorInjector;
use Go\Aop\Framework\Interceptor;
use Go\Aop\Framework\The;
use Go\Aop\Intercept\FieldAccess;
use App\Aspect\AuditAspect;
use App\Attribute\Auditable;
class Customer implements \Go\Aop\Proxy
same class name
{
use CustomerOriginalTrait;
the rest of your class
#[\App\Attribute\Auditable]
attribute kept
public string $email = '' {
native PHP 8.4 hooks
get {
/** @var FieldAccess<self, string> $__joinPoint */
typed for PHPStan and IDEs
static $__joinPoint = InterceptorInjector::forProperty(
self::class,
'email',
[
Interceptor::around(The::aspect(AuditAspect::class)->auditWrite(...)),
your audit behavior
],
);
return $__joinPoint->read($this, $this->email);
reads pass through
}
set {
/** @var FieldAccess<self, string> $__joinPoint */
static $__joinPoint = InterceptorInjector::forProperty(
self::class,
'email',
[
Interceptor::around(The::aspect(AuditAspect::class)->auditWrite(...)),
],
);
$this->email = $__joinPoint->write($this, $value, $this->email);
writes go through the behavior
}
}
#[\App\Attribute\Auditable]
public string $plan = 'free' {
get {
/** @var FieldAccess<self, string> $__joinPoint */
static $__joinPoint = InterceptorInjector::forProperty(
self::class,
'plan',
[
Interceptor::around(The::aspect(AuditAspect::class)->auditWrite(...)),
],
);
return $__joinPoint->read($this, $this->plan);
}
set {
/** @var FieldAccess<self, string> $__joinPoint */
static $__joinPoint = InterceptorInjector::forProperty(
self::class,
'plan',
[
Interceptor::around(The::aspect(AuditAspect::class)->auditWrite(...)),
],
);
$this->plan = $__joinPoint->write($this, $value, $this->plan);
}
}
}
Audit every change with one attribute
Mark the properties that matter with #[Auditable]. The audit behavior is attached to each of them as dynamic middleware: every write is recorded with the property name, the old value and the new one, wherever the write comes from.
- Every write of a marked property, from any code: outside, inside the class, the constructor
- The old and the new value, before the write lands
- Unmarked properties and reads cost nothing extra
- The entity keeps plain public properties: no setters, no __set()
#[\Attribute(\Attribute::TARGET_PROPERTY)]final class Auditable {}$customer->plan = 'pro'; // audit: plan, from "free" to "pro"$customer->upgrade('team'); // audit: plan, from "pro" to "team"$customer->displayName = 'Ann'; // no record: no #[Auditable]echo $customer->email; // reads pass through untouched
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Attribute\Auditable;
class Customer
{
#[Auditable]
audited
public string $email = '';
#[Auditable]
audited
public string $plan = 'free';
public string $displayName = '';
not audited
public function upgrade(string $plan): void
{
$this->plan = $plan;
}
}
<?php
namespace App\Aspect;
use Go\Aop\Aspect;
use Go\Aop\Intercept\FieldAccess;
use Go\Aop\Intercept\FieldAccessType;
use Go\Lang\Attribute\Around;
use Psr\Log\LoggerInterface;
final class AuditAspect implements Aspect
{
public function __construct(private LoggerInterface $audit) {}
#[Around('@access(App\Attribute\Auditable)')]
every #[Auditable] property
public function auditWrite(FieldAccess $access): mixed
{
if ($access->getAccessType() === FieldAccessType::Write) {
writes only
$this->audit->info('Property changed', [
'property' => $access->getField()->name,
'from' => $access->getValue(),
'to' => $access->getValueToSet(),
]);
}
return $access->proceed();
the value lands
}
}
Fast enough to leave on
Measurements and the full list of rules are in docs/advices.md and docs/performance.md.
- per access< 0.3 µsfor a property read or write through its middleware
- magic0no __get or __set: IDEs and PHPStan see real properties
- nativePHP 8.4woven into the language’s own property hooks
Select your own properties
Start from @access(App\Attribute\Auditable), then change it: every property it reaches lights up in the playground, line by line.
Try your pointcutEverything else in the box
- Pure PHPNo extensions. No black boxes. Just PHP.
- Intercept anythingNo method is off limits.
- DebuggableNo magic you can't step through.
- PerformanceZero cost without behaviors, under 1 µs with them.
- Pointcut languageSelect exactly the code you mean, and try it live.
- Class extensionsNew interfaces and traits for existing classes.
- Works with your stackSymfony, Laravel, Yii3 and your AI coding agent.