Debian Codegraph @

vendor/wikimedia/remex-html/src/PropGuard.php

raw
1 <?php
2
3 namespace Wikimedia\RemexHtml;
4
5 use InvalidArgumentException;
6
7 /**
8 * This is a statically configurable mechanism for preventing the setting of
9 * undeclared properties on objects. The point of it is to detect programmer
10 * errors.
11 */
12 trait PropGuard {
13 /** @var bool */
14 public static $armed = true;
15
16 public function __set( $name, $value ) {
17 if ( self::$armed ) {
18 throw new InvalidArgumentException( "Property \"$name\" on object of class " . get_class( $this ) .
19 " is undeclared" );
20 } else {
21 $this->$name = $value;
22 }
23 }
24 }