71 protected $deprecatedPublicProperties = [];
100 $this->deprecatedPublicProperties[$property] = [
127 ?callable $setter =
null,
131 $this->deprecatedPublicProperties[$property] = [
151 string $class =
null,
152 string $component =
null
154 $this->dynamicPropertiesAccessDeprecated = [ $version, $class ?: __CLASS__, $component ];
161 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
162 list( $version, $class, $component, $getter ) = $this->deprecatedPublicProperties[$name];
163 $qualifiedName = $class .
'::$' . $name;
164 wfDeprecated( $qualifiedName, $version, $component, 3 );
176 if ( $this->dynamicPropertiesAccessDeprecated ) {
178 $qualifiedName = $class .
'::$' . $name;
179 wfDeprecated( $qualifiedName, $version, $component, 3 );
186 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
187 list( $version, $class, $component, $getter ) = $this->deprecatedPublicProperties[$name];
188 $qualifiedName = $class .
'::$' . $name;
189 wfDeprecated( $qualifiedName, $version, $component, 3 );
197 $qualifiedName = ( $ownerClass ?: get_class( $this ) ) .
'::$' . $name;
200 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
201 } elseif ( property_exists( $this, $name ) ) {
209 trigger_error(
"Undefined property: $qualifiedName", E_USER_NOTICE );
214 public function __set( $name, $value ) {
215 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
216 list( $version, $class, $component, , $setter ) = $this->deprecatedPublicProperties[$name];
217 $qualifiedName = $class .
'::$' . $name;
218 wfDeprecated( $qualifiedName, $version, $component, 3 );
221 } elseif ( property_exists( $this, $name ) ) {
222 $this->$name = $value;
224 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
230 $qualifiedName = ( $ownerClass ?: get_class( $this ) ) .
'::$' . $name;
233 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
235 if ( $this->dynamicPropertiesAccessDeprecated ) {
237 $qualifiedName = $class .
'::$' . $name;
238 wfDeprecated( $qualifiedName, $version, $component, 3 );
241 $this->$name = $value;
255 $obfuscatedProps = array_keys( (array)$this );
256 $obfuscatedPropTail =
"\0$property";
257 foreach ( $obfuscatedProps as $obfuscatedProp ) {
259 if ( strpos( $obfuscatedProp, $obfuscatedPropTail, 1 ) !==
false ) {
260 $classname = substr( $obfuscatedProp, 1, -strlen( $obfuscatedPropTail ) );
261 if ( $classname ===
'*' ) {
264 return (
new ReflectionProperty( $this, $property ) )->getDeclaringClass()->getName();
deprecatePublicProperty( $property, $version, $class=null, $component=null)
Mark a property as deprecated.
deprecatePublicPropertyFallback(string $property, string $version, callable $getter, ?callable $setter=null, $class=null, $component=null)
Mark a removed public property as deprecated and provide fallback getter and setter callables.
deprecateDynamicPropertiesAccess(string $version, string $class=null, string $component=null)
Emit deprecation warnings when dynamic and unknown properties are accessed.
bool array $dynamicPropertiesAccessDeprecated
Whether to emit a deprecation warning when unknown properties are accessed.
trait DeprecationHelper
Use this trait in classes which have properties for which public access is deprecated or implementati...
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)
Logs a warning that a deprecated feature was used.