55 protected $deprecatedPublicProperties = [];
69 $property, $version, $class =
null, $component =
null
71 $this->deprecatedPublicProperties[$property] = [ $version, $class ?: __CLASS__, $component ];
74 public function __get( $name ) {
75 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
76 list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
77 $qualifiedName = $class .
'::$' . $name;
83 $qualifiedName = ( $ownerClass ?: get_class( $this ) ) .
'::$' . $name;
86 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
89 trigger_error(
"Undefined property: $qualifiedName", E_USER_NOTICE );
94 public function __set( $name, $value ) {
95 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
96 list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
97 $qualifiedName = $class .
'::$' . $name;
99 $this->$name = $value;
104 $qualifiedName = ( $ownerClass ?: get_class( $this ) ) .
'::$' . $name;
107 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
110 $this->$name = $value;
124 $obfuscatedProps = array_keys( (array)$this );
125 $obfuscatedPropTail =
"\0$property";
126 foreach ( $obfuscatedProps as $obfuscatedProp ) {
128 if ( strpos( $obfuscatedProp, $obfuscatedPropTail, 1 ) !==
false ) {
129 $classname = substr( $obfuscatedProp, 1, -strlen( $obfuscatedPropTail ) );
130 if ( $classname ===
'*' ) {
133 return (
new ReflectionProperty( $this, $property ) )->getDeclaringClass()->getName();
deprecatePublicProperty( $property, $version, $class=null, $component=null)
Mark a property as deprecated.
trait DeprecationHelper
Use this trait in classes which have properties for which public access is deprecated.
deprecationHelperGetPropertyOwner( $property)
Like property_exists but also check for non-visible private properties and returns which class in the...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.