Page MenuHomePhabricator

Deprecate direct access to class variables
Closed, DeclinedPublic


In MW 1.24 an effort was made to improve code quality by making it phpcs-strict compliant [0]. This involves explicitly declaring the visibility of class members. In the course of this, in many cases the class variable's visibility was changed from the implicit 'public' to explicit 'protected' or 'private', thus introducing a major API change without proper deprecation period.

To keep the changes and still be able to properly deprecate the direct access to the member variables a patch [1] was submitted that makes use of PHP magic functions [2]. The introduced functions provide access to the formerly public class members and issue a deprecation warning. For old PHP versions a warning by Tim Starling existed [4], to avoid __get(). However, this does not apply to the current case, as the __get method is not used re-entrantly. Moreover, it is questionable, whether this warning is still valid for recent versions of PHP.


The intention is to keep these functions for the custom two releases [3], i.e. until 1.26, and then remove them.

Affected classes, files and action required for removal:

  • CategoryViewer (CategoryViewer.php; delete magic functions)
  • EditPage (EditPage.php; delete magic functions)
  • WikiExporter (Export.php; delete magic functions)
  • DumpLatestFilter (Export.php; delete magic functions)
  • FeedItem (Feed.php; delete magic functions)
  • DiffHistoryBlob (HistoryBlob.php; delete magic functions)
  • WikiRevision (Import.php; delete magic functions)
  • Article (Article.php; delete magic functions __isset() and __unset(), modify __get() and __set() to not return private variables of Article anymore)



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 3:37 AM
bzimport set Reference to bz69939.
bzimport added a subscriber: Unknown Object (MLST).
Krinkle set Security to None.
Krinkle removed subscribers: Krinkle, Unknown Object (MLST).

There exists a helper for this purpose now in core (DeprecationHelper triat). It uses __get and I assume that the concern with that for "old PHP versions" no longer applies, given we now require PHP 5.6+/HHVM.

I'm closing this in favour of individual tasks to be filed by maintainers for specific classes or components in which they wish to deprecate public members.