hooks: Stop suggesting to pass objects by reference
It looks like the examples section on top of the hooks.txt file still suggests to pass objects by reference. This is an obsolete relict from PHP 4 and not needed any more. Bug: T193950 Change-Id: I61bdc4a313401955943903918ff8167c2bea5aac
This commit is contained in:
parent
3039165854
commit
210483fc16
2 changed files with 10 additions and 13 deletions
|
|
@ -74,10 +74,10 @@ Using a hook-running strategy, we can avoid having all this option-specific
|
|||
stuff in our mainline code. Using hooks, the function becomes:
|
||||
|
||||
function showAnArticle( $article ) {
|
||||
if ( Hooks::run( 'ArticleShow', [ &$article ] ) ) {
|
||||
if ( Hooks::run( 'ArticleShow', [ $article ] ) ) {
|
||||
# code to actually show the article goes here
|
||||
|
||||
Hooks::run( 'ArticleShowComplete', [ &$article ] );
|
||||
Hooks::run( 'ArticleShowComplete', [ $article ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,15 +91,15 @@ title-reversing if-blocks spread all over the codebase in showAnArticle,
|
|||
deleteAnArticle, exportArticle, etc., we can concentrate it all in an extension
|
||||
file:
|
||||
|
||||
function onArticleShow( &$article ) {
|
||||
function onArticleShow( $article ) {
|
||||
# ...
|
||||
}
|
||||
|
||||
function onArticleDelete( &$article ) {
|
||||
function onArticleDelete( $article ) {
|
||||
# ...
|
||||
}
|
||||
|
||||
function onArticleExport( &$article ) {
|
||||
function onArticleExport( $article ) {
|
||||
# ...
|
||||
}
|
||||
|
||||
|
|
@ -217,12 +217,9 @@ related to a particular event, like so:
|
|||
function protect() {
|
||||
global $wgUser;
|
||||
|
||||
// Avoid PHP 7.1 warning from passing $this by reference
|
||||
$article = $this;
|
||||
|
||||
if ( Hooks::run( 'ArticleProtect', [ &$article, &$wgUser ] ) ) {
|
||||
if ( Hooks::run( 'ArticleProtect', [ $this, $wgUser ] ) ) {
|
||||
# protect the article
|
||||
Hooks::run( 'ArticleProtectComplete', [ &$article, &$wgUser ] );
|
||||
Hooks::run( 'ArticleProtectComplete', [ $this, $wgUser ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ function wfAddCustomMagicWordID( &$magicWords ) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function wfGetCustomMagicWordValue( $parser, &$variableCache, &$magicWordId, &$ret ){
|
||||
function wfGetCustomMagicWordValue( $parser, &$variableCache, $magicWordId, &$ret ){
|
||||
if( $magicWordId == 'mag_custom' ){
|
||||
$ret = $variableCache['mag_custom'] = "Custom value";
|
||||
}
|
||||
|
|
@ -77,12 +77,12 @@ $magicWords['es'] = [
|
|||
$wgExtensionMessagesFiles['ExtensionNameMagic'] = __DIR__ . '/ExtensionName.i18n.magic.php';
|
||||
$wgHooks['ParserFirstCallInit'][] = 'wfRegisterCustomMagicWord';
|
||||
|
||||
function wfRegisterCustomMagicWord( &$parser ){
|
||||
function wfRegisterCustomMagicWord( $parser ){
|
||||
$parser->setFunctionHook( 'mag_custom', 'wfGetCustomMagicWordValue' );
|
||||
return true;
|
||||
}
|
||||
|
||||
function wfGetCustomMagicWordValue( &$parser, $var1, $var2 ){
|
||||
function wfGetCustomMagicWordValue( $parser, $var1, $var2 ){
|
||||
return "custom: var1 is $var1, var2 is $var2";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue