MediaWiki  1.34.0
DeprecationHelper.php File Reference

Trait for issuing warnings on deprecated access. More...

Go to the source code of this file.

Functions

 __get ( $name)
 
 __set ( $name, $value)
 
 deprecatePublicProperty ( $property, $version, $class=null, $component=null)
 Mark a property as deprecated. More...
 
 deprecationHelperGetPropertyOwner ( $property)
 Like property_exists but also check for non-visible private properties and returns which class in the inheritance chain declared the property. More...
 

Variables

trait DeprecationHelper
 Use this trait in classes which have properties for which public access is deprecated. More...
 

Detailed Description

Trait for issuing warnings on deprecated access.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html

Definition in file DeprecationHelper.php.

Function Documentation

◆ __get()

__get (   $name)

Definition at line 74 of file DeprecationHelper.php.

References deprecationHelperGetPropertyOwner(), and wfDeprecated().

◆ __set()

__set (   $name,
  $value 
)

Definition at line 94 of file DeprecationHelper.php.

References deprecationHelperGetPropertyOwner(), and wfDeprecated().

◆ deprecatePublicProperty()

deprecatePublicProperty (   $property,
  $version,
  $class = null,
  $component = null 
)
protected

Mark a property as deprecated.

Only use this for properties that used to be public and only call it in the constructor.

Parameters
string$propertyThe name of the property.
string$versionMediaWiki version where the property became deprecated.
string | null$classThe class which has the deprecated property. This can usually be guessed, but PHP can get confused when both the parent class and the subclass use the trait, so it should be specified in classes meant for subclassing.
string | null$component
See also
wfDeprecated()

Definition at line 68 of file DeprecationHelper.php.

Referenced by DifferenceEngine\__construct().

◆ deprecationHelperGetPropertyOwner()

deprecationHelperGetPropertyOwner (   $property)
private

Like property_exists but also check for non-visible private properties and returns which class in the inheritance chain declared the property.

Parameters
string$property
Returns
string|bool Best guess for the class in which the property is defined. False if the object does not have such a property.

Definition at line 121 of file DeprecationHelper.php.

Referenced by __get(), and __set().

Variable Documentation

◆ DeprecationHelper

trait DeprecationHelper
Initial value:
{
protected string[][] $deprecatedPublicProperties = []

Use this trait in classes which have properties for which public access is deprecated.

Set the list of properties in $deprecatedPublicProperties and make the properties non-public. The trait will preserve public access but issue deprecation warnings when it is needed.

Example usage: class Foo { use DeprecationHelper; protected $bar; public function construct() { $this->deprecatePublicProperty( 'bar', '1.21', __CLASS ); } }

$foo = new Foo; $foo->bar; // works but logs a warning

Cannot be used with classes that have their own __get/__set methods.

Since
1.32

Definition at line 45 of file DeprecationHelper.php.