Skip to content

Commit 883d85a

Browse files
committed
add property hook
1 parent 403c9e9 commit 883d85a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

snippet/php_84/property_hook.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpParser\Modifiers;
6+
7+
$propertyItem = new \PhpParser\Node\PropertyItem('someProperty');
8+
$property = new \PhpParser\Node\Stmt\Property(Modifiers::PUBLIC, [$propertyItem]);
9+
10+
$plus = new \PhpParser\Node\Expr\BinaryOp\Plus(
11+
new \PhpParser\Node\Expr\Variable('variable'),
12+
new \PhpParser\Node\Scalar\Int_(100)
13+
);
14+
15+
$getPropertyHook = new \PhpParser\Node\PropertyHook('getProperty', $plus);
16+
17+
$property->hooks[] = $getPropertyHook;
18+
19+
return $property;

0 commit comments

Comments
 (0)