CINXE.COM

Manual:Coding conventions/PHP - MediaWiki

<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-disabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref--excluded vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-disabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Manual:Coding conventions/PHP - MediaWiki</title> <script>(function(){var className="client-js vector-feature-language-in-header-disabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref--excluded vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-disabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )mediawikiwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""], "wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"4c7d79e1-4958-45b4-8668-6d9b7f821e50","wgCanonicalNamespace":"Manual","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":100,"wgPageName":"Manual:Coding_conventions/PHP","wgTitle":"Coding conventions/PHP","wgCurRevisionId":6854458,"wgRevisionId":6854458,"wgArticleId":75216,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Development guidelines"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Manual:Coding_conventions/PHP","wgRelevantArticleId":75216,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"mediawiki","wgCiteReferencePreviewsActive":true,"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault": true,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":50000,"wgInternalRedirectTargetUrl":"/wiki/Manual:Coding_conventions/PHP","wgTranslatePageTranslation":"source","wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"personal","wgULSisCompactLinksEnabled":true,"wgVector2022LanguageInHeader":false,"wgULSisLanguageSelectorEmpty":false,"wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"]};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.translate.tag.languages":"ready","ext.pygments":"ready","ext.cite.styles":"ready","skins.vector.search.codex.styles" :"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","ext.translate.edit.documentation.styles":"ready","ext.translate":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.pt":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["mediawiki.action.view.redirect","ext.pygments.view","ext.cite.ux-enhancements","site","mediawiki.page.ready","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.translate.pagetranslation.uls","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.compactlinks","ext.uls.interface","ext.checkUser.clientHints"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=ext.cite.styles%7Cext.pygments%2Ctranslate%2CwikimediaBadges%7Cext.translate.edit.documentation.styles%7Cext.translate.tag.languages%7Cext.uls.pt%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022"> <script async="" src="/w/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.4"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:site_name" content="MediaWiki"> <meta property="og:title" content="Manual:Coding conventions/PHP - MediaWiki"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//m.mediawiki.org/wiki/Manual:Coding_conventions/PHP"> <link rel="alternate" type="application/x-wiki" title="Edit" href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/mediawiki.png"> <link rel="icon" href="/static/favicon/mediawiki.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="MediaWiki (en)"> <link rel="EditURI" type="application/rsd+xml" href="//www.mediawiki.org/w/api.php?action=rsd"> <link rel="canonical" href="https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"> <link rel="alternate" type="application/atom+xml" title="MediaWiki Atom feed" href="/w/index.php?title=Special:RecentChanges&amp;feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="//login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-100 ns-subject mw-editable page-Manual_Coding_conventions_PHP rootpage-Manual_Coding_conventions skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/MediaWiki" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-mw-download" class="mw-list-item"><a href="/wiki/Download"><span>Get MediaWiki</span></a></li><li id="n-mw-extensions" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Category:Extensions"><span>Get extensions</span></a></li><li id="n-blog-text" class="mw-list-item"><a href="https://techblog.wikimedia.org/"><span>Tech blog</span></a></li><li id="n-mw-contribute" class="mw-list-item"><a href="/wiki/Special:MyLanguage/How_to_contribute"><span>Contribute</span></a></li> </ul> </div> </div> <div id="p-support" class="vector-menu mw-portlet mw-portlet-support" > <div class="vector-menu-heading"> Support </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Help:Contents" title="The place to find out"><span>User help</span></a></li><li id="n-mw-faq" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Manual:FAQ"><span>FAQ</span></a></li><li id="n-mw-manual" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Manual:Contents"><span>Technical manual</span></a></li><li id="n-mw-supportdesk" class="mw-list-item"><a href="/wiki/Project:Support_desk"><span>Support desk</span></a></li><li id="n-mw-communication" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Communication"><span>Communication</span></a></li> </ul> </div> </div> <div id="p-development" class="vector-menu mw-portlet mw-portlet-development" > <div class="vector-menu-heading"> Development </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mw-developerportal" class="mw-list-item"><a href="https://developer.wikimedia.org/"><span>Developer portal</span></a></li><li id="n-svn-statistics" class="mw-list-item"><a href="/wiki/Development_statistics"><span>Code statistics</span></a></li> </ul> </div> </div> <div id="p-mediawiki.org" class="vector-menu mw-portlet mw-portlet-mediawiki_org" > <div class="vector-menu-heading"> mediawiki.org </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-portal" class="mw-list-item"><a href="/wiki/Project:Help" title="About the project, what you can do, where to find things"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes in the wiki [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-mw-translate" class="mw-list-item"><a href="/wiki/Special:LanguageStats"><span>Translate content</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Load a random page [x]" accesskey="x"><span>Random page</span></a></li><li id="n-mw-discussion" class="mw-list-item"><a href="/wiki/Project:Village_Pump"><span>Village pump</span></a></li><li id="n-Sandboxlink-portlet-label" class="mw-list-item"><a href="/wiki/Project:Sandbox"><span>Sandbox</span></a></li> </ul> </div> </div> <div id="p-lang" class="vector-menu mw-portlet mw-portlet-lang" > <div class="vector-menu-heading"> In other languages </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-add wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:NewItem?site=mediawikiwiki&amp;page=Manual%3ACoding+conventions%2FPHP" title="Add interlanguage links" class="wbc-editpage">Add links</a></span></div> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/MediaWiki" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/mediawikiwiki.svg" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="MediaWiki" src="/static/images/mobile/copyright/mediawikiwiki-wordmark.svg" style="width: 7.5em; height: 1.125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search MediaWiki [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search MediaWiki" aria-label="Search MediaWiki" autocapitalize="sentences" title="Search MediaWiki [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-uls" class="mw-list-item active user-links-collapsible-item"><a data-mw="interface" href="#" class="uls-trigger cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet"><span class="vector-icon mw-ui-icon-wikimedia-language mw-ui-icon-wikimedia-wikimedia-language"></span> <span>English</span></a> </li> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page&#039;s font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=spontaneous&amp;uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&amp;returnto=Manual%3ACoding+conventions%2FPHP" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&amp;returnto=Manual%3ACoding+conventions%2FPHP" title="You are encouraged to log in; however, it is not mandatory [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="More options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=spontaneous&amp;uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&amp;returnto=Manual%3ACoding+conventions%2FPHP" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=Manual%3ACoding+conventions%2FPHP" title="You are encouraged to log in; however, it is not mandatory [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">Beginning</div> </a> </li> <li id="toc-Code_structure" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Code_structure"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Code structure</span> </div> </a> <button aria-controls="toc-Code_structure-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Code structure subsection</span> </button> <ul id="toc-Code_structure-sublist" class="vector-toc-list"> <li id="toc-Spaces" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Spaces"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1</span> <span>Spaces</span> </div> </a> <ul id="toc-Spaces-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Ternary_operator" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Ternary_operator"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.2</span> <span>Ternary operator</span> </div> </a> <ul id="toc-Ternary_operator-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-String_literals" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#String_literals"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3</span> <span>String literals</span> </div> </a> <ul id="toc-String_literals-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Functions_and_parameters" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Functions_and_parameters"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.4</span> <span>Functions and parameters</span> </div> </a> <ul id="toc-Functions_and_parameters-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Assignment_expressions" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Assignment_expressions"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.5</span> <span>Assignment expressions</span> </div> </a> <ul id="toc-Assignment_expressions-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-C_borrowings" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#C_borrowings"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.6</span> <span>C borrowings</span> </div> </a> <ul id="toc-C_borrowings-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Alternative_syntax_for_control_structures" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Alternative_syntax_for_control_structures"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.7</span> <span>Alternative syntax for control structures</span> </div> </a> <ul id="toc-Alternative_syntax_for_control_structures-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Brace_placement" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Brace_placement"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.8</span> <span>Brace placement</span> </div> </a> <ul id="toc-Brace_placement-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Type_declarations_in_function_parameters" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Type_declarations_in_function_parameters"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.9</span> <span>Type declarations in function parameters</span> </div> </a> <ul id="toc-Type_declarations_in_function_parameters-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Naming" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Naming"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Naming</span> </div> </a> <button aria-controls="toc-Naming-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Naming subsection</span> </button> <ul id="toc-Naming-sublist" class="vector-toc-list"> <li id="toc-Prefixes" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Prefixes"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1</span> <span>Prefixes</span> </div> </a> <ul id="toc-Prefixes-sublist" class="vector-toc-list"> <li id="toc-Function_names" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Function_names"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1.1</span> <span>Function names</span> </div> </a> <ul id="toc-Function_names-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Variable_names" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Variable_names"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1.2</span> <span>Variable names</span> </div> </a> <ul id="toc-Variable_names-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> </ul> </li> <li id="toc-Pitfalls" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Pitfalls"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Pitfalls</span> </div> </a> <button aria-controls="toc-Pitfalls-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Pitfalls subsection</span> </button> <ul id="toc-Pitfalls-sublist" class="vector-toc-list"> <li id="toc-empty()" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#empty()"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1</span> <span>empty()</span> </div> </a> <ul id="toc-empty()-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-isset()" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#isset()"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.2</span> <span>isset()</span> </div> </a> <ul id="toc-isset()-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Boolean_conversion" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Boolean_conversion"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3</span> <span>Boolean conversion</span> </div> </a> <ul id="toc-Boolean_conversion-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Other" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Other"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.4</span> <span>Other</span> </div> </a> <ul id="toc-Other-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Equality_operators" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Equality_operators"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5</span> <span>Equality operators</span> </div> </a> <ul id="toc-Equality_operators-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-JSON_number_precision" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#JSON_number_precision"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6</span> <span>JSON number precision</span> </div> </a> <ul id="toc-JSON_number_precision-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Dos_and_don&#039;ts" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Dos_and_don&#039;ts"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Dos and don'ts</span> </div> </a> <button aria-controls="toc-Dos_and_don&#039;ts-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Dos and don'ts subsection</span> </button> <ul id="toc-Dos_and_don&#039;ts-sublist" class="vector-toc-list"> <li id="toc-Don&#039;t_use_built_in_serialization" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Don&#039;t_use_built_in_serialization"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1</span> <span>Don't use built in serialization</span> </div> </a> <ul id="toc-Don&#039;t_use_built_in_serialization-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Don&#039;t_add_type_declarations_for_&quot;big&quot;_legacy_classes" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Don&#039;t_add_type_declarations_for_&quot;big&quot;_legacy_classes"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2</span> <span>Don't add type declarations for "big" legacy classes</span> </div> </a> <ul id="toc-Don&#039;t_add_type_declarations_for_&quot;big&quot;_legacy_classes-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Comments_and_documentation" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Comments_and_documentation"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>Comments and documentation</span> </div> </a> <button aria-controls="toc-Comments_and_documentation-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Comments and documentation subsection</span> </button> <ul id="toc-Comments_and_documentation-sublist" class="vector-toc-list"> <li id="toc-Source_file_headers" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Source_file_headers"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1</span> <span>Source file headers</span> </div> </a> <ul id="toc-Source_file_headers-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Doxygen_tags" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Doxygen_tags"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2</span> <span>Doxygen tags</span> </div> </a> <ul id="toc-Doxygen_tags-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Test_annotations" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Test_annotations"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.3</span> <span>Test annotations</span> </div> </a> <ul id="toc-Test_annotations-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Integration" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Integration"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Integration</span> </div> </a> <ul id="toc-Integration-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Visibility" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Visibility"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>Visibility</span> </div> </a> <button aria-controls="toc-Visibility-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Visibility subsection</span> </button> <ul id="toc-Visibility-sublist" class="vector-toc-list"> <li id="toc-Global_objects" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Global_objects"> <div class="vector-toc-text"> <span class="vector-toc-numb">7.1</span> <span>Global objects</span> </div> </a> <ul id="toc-Global_objects-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Static_methods" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Static_methods"> <div class="vector-toc-text"> <span class="vector-toc-numb">7.2</span> <span>Static methods</span> </div> </a> <ul id="toc-Static_methods-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Calling_methods" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Calling_methods"> <div class="vector-toc-text"> <span class="vector-toc-numb">7.3</span> <span>Calling methods</span> </div> </a> <ul id="toc-Calling_methods-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Classes" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Classes"> <div class="vector-toc-text"> <span class="vector-toc-numb">7.4</span> <span>Classes</span> </div> </a> <ul id="toc-Classes-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Error_handling" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Error_handling"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>Error handling</span> </div> </a> <button aria-controls="toc-Error_handling-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Error handling subsection</span> </button> <ul id="toc-Error_handling-sublist" class="vector-toc-list"> <li id="toc-AtEase" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#AtEase"> <div class="vector-toc-text"> <span class="vector-toc-numb">8.1</span> <span>AtEase</span> </div> </a> <ul id="toc-AtEase-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Exception_handling" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Exception_handling"> <div class="vector-toc-text"> <span class="vector-toc-numb">9</span> <span>Exception handling</span> </div> </a> <ul id="toc-Exception_handling-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-See_also" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#See_also"> <div class="vector-toc-text"> <span class="vector-toc-numb">10</span> <span>See also</span> </div> </a> <ul id="toc-See_also-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Notes" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Notes"> <div class="vector-toc-text"> <span class="vector-toc-numb">11</span> <span>Notes</span> </div> </a> <ul id="toc-Notes-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-namespace">Manual</span><span class="mw-page-title-separator">:</span><span class="mw-page-title-main">Coding conventions/PHP</span></h1> <div class="mw-indicators"> <div id="mw-indicator-tpl-shortcut" class="mw-indicator"><div class="mw-parser-output"><div class="mw-parser-output"><style data-mw-deduplicate="TemplateStyles:r6605561">.mw-parser-output .tpl-badge{background-color:var(--background-color-progressive-subtle,#eaf3ff);color:var(--color-base,#202122);border-radius:10px;display:inline-block;font-size:90%;padding:5px 8px}</style><div class="tpl-badge">shortcut: <a href="/wiki/CC/PHP" class="mw-redirect" title="CC/PHP"><b>CC/PHP</b></a></div></div></div></div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-manual" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Manual:Coding_conventions/PHP" title="View the subject page [c]" accesskey="c"><span>Manual</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Manual_talk:Coding_conventions/PHP" rel="discussion" class="mw-redirect" title="Discussion about the content page [t]" accesskey="t"><span>Discussion</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Manual:Coding_conventions/PHP"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit" title="Edit the source code of this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Manual:Coding_conventions/PHP"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit" title="Edit the source code of this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Manual:Coding_conventions/PHP" title="A list of all wiki pages that link here [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Manual:Coding_conventions/PHP" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="//commons.wikimedia.org/wiki/Special:UploadWizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;oldid=6854458" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&amp;page=Manual%3ACoding_conventions%2FPHP&amp;id=6854458&amp;wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&amp;url=https%3A%2F%2Fwww.mediawiki.org%2Fwiki%2FManual%3ACoding_conventions%2FPHP"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrCode&amp;url=https%3A%2F%2Fwww.mediawiki.org%2Fwiki%2FManual%3ACoding_conventions%2FPHP"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-create_a_book" class="mw-list-item"><a href="/w/index.php?title=Special:Book&amp;bookcmd=book_creator&amp;referer=Manual%3ACoding+conventions%2FPHP"><span>Create a book</span></a></li><li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&amp;page=Manual%3ACoding_conventions%2FPHP&amp;action=show-download-screen"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects emptyPortlet" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div id="siteSub" class="noprint">From mediawiki.org</div> </div> <div id="contentSub"><div id="mw-content-subtitle"><div class="subpages">&lt; <bdi dir="ltr"><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions" title="Special:MyLanguage/Manual:Coding conventions">Manual:Coding conventions</a></bdi></div></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-pt-translate-header noprint nomobile" dir="ltr" lang="en"><a href="/w/index.php?title=Special:Translate&amp;group=page-Manual%3ACoding+conventions%2FPHP&amp;action=page&amp;filter=&amp;action_source=translate_page" title="Special:Translate">Translate this page</a></div><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="mw-pt-languages noprint navigation-not-searchable" lang="en" dir="ltr"><div class="mw-pt-languages-label">Languages:</div><ul class="mw-pt-languages-list"><li><a href="/wiki/Manual:Coding_conventions/PHP/de" class="mw-pt-progress mw-pt-progress--low" title="Handbuch:Kodierungskonventionen/PHP (9% translated)" lang="de" dir="ltr">Deutsch</a></li> <li><span class="mw-pt-languages-ui mw-pt-languages-selected mw-pt-progress mw-pt-progress--complete" lang="en" dir="ltr">English</span></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/yo" class="mw-pt-progress mw-pt-progress--low" title="Manual:Coding conventions/PHP/yo (1% translated)" lang="yo" dir="ltr">Yorùbá</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/da" class="mw-pt-progress mw-pt-progress--low" title="Manual:Coding conventions/PHP (4% translated)" lang="da" dir="ltr">dansk</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/es" class="mw-pt-progress mw-pt-progress--low" title="Manual:Coding conventions/PHP/es (3% translated)" lang="es" dir="ltr">español</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/fr" class="mw-pt-progress mw-pt-progress--high" title="Manuel:Conventions de codage/PHP (93% translated)" lang="fr" dir="ltr">français</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/pl" class="mw-pt-progress mw-pt-progress--low" title="Podręcznik:Konwencje kodowania/PHP (3% translated)" lang="pl" dir="ltr">polski</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/cs" class="mw-pt-progress mw-pt-progress--high" title="Příručka:Konvence pro psaní kódu/PHP (93% translated)" lang="cs" dir="ltr">čeština</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/ru" class="mw-pt-progress mw-pt-progress--low" title="Manual:Coding conventions/PHP/ru (1% translated)" lang="ru" dir="ltr">русский</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/zh" class="mw-pt-progress mw-pt-progress--low" title="手册:代码编写约定/PHP (7% translated)" lang="zh" dir="ltr">中文</a></li> <li><a href="/wiki/Manual:Coding_conventions/PHP/ja" class="mw-pt-progress mw-pt-progress--high" title="Manual:コーディング規約/PHP (70% translated)" lang="ja" dir="ltr">日本語</a></li></ul></div> <style data-mw-deduplicate="TemplateStyles:r6651108">.mw-parser-output table.ombox{margin:4px 10%;border-collapse:collapse;border:1px solid #a2a9b1;background-color:#f8f9fa;color:#333;box-sizing:border-box}.mw-parser-output .ombox td.mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ombox th.mbox-text,.mw-parser-output .ombox td.mbox-text{border:none;padding:0.25em 0.9em;width:100%}.mw-parser-output .ombox td.mbox-image{border:none;text-align:center;padding:2px 0 2px 0.9em}.mw-parser-output .ombox td.mbox-imageright{border:none;text-align:center;padding:2px 0.9em 2px 0}.mw-parser-output table.ombox-notice{border-color:#a2a9b1}.mw-parser-output table.ombox-speedy{background-color:#fee7e6;color:#333}.mw-parser-output table.ombox-speedy,.mw-parser-output table.ombox-delete{border-color:#b32424;border-width:2px}.mw-parser-output table.ombox-content{border-color:#f28500}.mw-parser-output table.ombox-style{border-color:#fc3}.mw-parser-output table.ombox-move{border-color:#9932cc}.mw-parser-output table.ombox-protection{border-color:#a2a9b1;border-width:2px}html body.mediawiki .mw-parser-output .ombox.mbox-small{clear:right;float:right;margin:4px 0 4px 1em;box-sizing:border-box;width:238px;font-size:88%;line-height:1.25em}@media screen{html.skin-theme-clientpref-night .mw-parser-output table.ombox{background-color:transparent;color:inherit}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output table.ombox{background-color:transparent;color:inherit}}</style><table class="ombox ombox-notice plainlinks" role="presentation"><tbody><tr><td class="mbox-image"><span typeof="mw:File"><span><img src="//upload.wikimedia.org/wikipedia/commons/thumb/f/f6/OOjs_UI_icon_check-constructive.svg/30px-OOjs_UI_icon_check-constructive.svg.png" decoding="async" width="30" height="30" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/f/f6/OOjs_UI_icon_check-constructive.svg/45px-OOjs_UI_icon_check-constructive.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/f/f6/OOjs_UI_icon_check-constructive.svg/60px-OOjs_UI_icon_check-constructive.svg.png 2x" data-file-width="20" data-file-height="20" /></span></span></td><td class="mbox-text">This page documents a MediaWiki <a href="/wiki/Special:MyLanguage/Development_guidelines" title="Special:MyLanguage/Development guidelines">development guideline</a>, crafted over time by developer consensus (or sometimes by proclamation from a lead developer)</td></tr></tbody></table> <p>This page describes the <b>coding conventions</b> used within files of the <a href="/wiki/Special:MyLanguage/Manual:Code" title="Special:MyLanguage/Manual:Code">MediaWiki codebase</a><span style="display:none"><a href="/wiki/Manual:Code" title="Manual:Code"> </a></span> written in <b>PHP</b>. See also the <a href="/wiki/Special:MyLanguage/Manual:Coding_conventions#All_languages" title="Special:MyLanguage/Manual:Coding conventions">general conventions</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions#All_languages" title="Manual:Coding conventions"> </a></span> that apply to all program languages, including PHP. If you would like a short checklist to help you review your commits, try using the <a href="/wiki/Special:MyLanguage/Manual:Pre-commit_checklist" title="Special:MyLanguage/Manual:Pre-commit checklist">Pre-commit checklist</a><span style="display:none"><a href="/wiki/Manual:Pre-commit_checklist" title="Manual:Pre-commit checklist"> </a></span>. </p><p>Most of the code style rules can be automatically fixed, or at least detected, by PHP_CodeSniffer (aka PHPCS), using a <a href="https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/tools/codesniffer" class="extiw" title="gerrit:plugins/gitiles/mediawiki/tools/codesniffer">custom ruleset for MediaWiki</a>. For more information, see <a href="/wiki/Special:MyLanguage/Continuous_integration/PHP_CodeSniffer" title="Special:MyLanguage/Continuous integration/PHP CodeSniffer">Continuous integration/PHP CodeSniffer</a><span style="display:none"><a href="/wiki/Continuous_integration/PHP_CodeSniffer" title="Continuous integration/PHP CodeSniffer"> </a></span>. </p> <div style="clear: right; margin-bottom: .5em; float: right; margin-left:2em; width: auto;"><meta property="mw:PageProp/toc" /></div> <div class="mw-heading mw-heading2"><h2 id="Code_structure">Code structure</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=1" title="Edit section: Code structure"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="Spaces">Spaces</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=2" title="Edit section: Spaces"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>MediaWiki favors a heavily-spaced style for optimum readability. </p><p>Indent with tabs, not spaces. Limit lines to 120 characters (given a tab-width of 4 characters). </p><p>Put spaces on either side of binary operators, for example: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// No:</span> <span class="nv">$a</span><span class="o">=</span><span class="nv">$b</span><span class="o">+</span><span class="nv">$c</span><span class="p">;</span> <span class="c1">// Yes:</span> <span class="nv">$a</span> <span class="o">=</span> <span class="nv">$b</span> <span class="o">+</span> <span class="nv">$c</span><span class="p">;</span> </pre></div> <p>Put spaces next to parentheses on the inside, except where the parentheses are empty. Do not put a space following a function name. </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$a</span> <span class="o">=</span> <span class="nx">getFoo</span><span class="p">(</span> <span class="nv">$b</span> <span class="p">);</span> <span class="nv">$c</span> <span class="o">=</span> <span class="nx">getBar</span><span class="p">();</span> </pre></div> <p>Put a space after the <code>:</code> in the function return type hint, but not before: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">function</span> <span class="nf">square</span><span class="p">(</span> <span class="nx">int</span> <span class="nv">$x</span> <span class="p">)</span><span class="o">:</span> <span class="nx">int</span> <span class="p">{</span> <span class="k">return</span> <span class="nv">$x</span> <span class="o">*</span> <span class="nv">$x</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>Put spaces in brackets when declaring an array, except where the array is empty. Do not put spaces in brackets when accessing array elements. </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// Yes</span> <span class="nv">$a</span> <span class="o">=</span> <span class="p">[</span> <span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span> <span class="p">];</span> <span class="nv">$c</span> <span class="o">=</span> <span class="nv">$a</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span> <span class="nv">$x</span> <span class="o">=</span> <span class="p">[];</span> <span class="c1">// No</span> <span class="nv">$a</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">];</span> <span class="nv">$c</span> <span class="o">=</span> <span class="nv">$a</span><span class="p">[</span> <span class="mi">0</span> <span class="p">];</span> <span class="nv">$x</span> <span class="o">=</span> <span class="p">[</span> <span class="p">];</span> </pre></div> <p>Control structures such as <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">if</span></code>, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">while</span></code>, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">for</span></code>, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">foreach</span></code>, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">switch</span></code>, as well as the <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">catch</span></code> keyword, should be followed by a space: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// Yes</span> <span class="k">if</span> <span class="p">(</span> <span class="nx">isFoo</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span> <span class="nv">$a</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// No</span> <span class="k">if</span><span class="p">(</span> <span class="nx">isFoo</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span> <span class="nv">$a</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>When type casting, do not use a space within or after the cast operator: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// Yes</span> <span class="p">(</span><span class="nx">int</span><span class="p">)</span><span class="nv">$foo</span><span class="p">;</span> <span class="c1">// No</span> <span class="p">(</span><span class="nx">int</span><span class="p">)</span> <span class="nv">$bar</span><span class="p">;</span> <span class="p">(</span> <span class="nx">int</span> <span class="p">)</span><span class="nv">$bar</span><span class="p">;</span> <span class="p">(</span> <span class="nx">int</span> <span class="p">)</span> <span class="nv">$bar</span><span class="p">;</span> </pre></div> <p>In comments there should be one space between the <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="c1">#</span></code> or <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="c1">//</span></code> character and the comment. </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// Yes: Proper inline comment</span> <span class="c1">//No: Missing space</span> <span class="sd">/***** Do not comment like this ***/</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Ternary_operator">Ternary operator</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=3" title="Edit section: Ternary operator"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The <a rel="nofollow" class="external text" href="https://php.net/language.operators.comparison">ternary operator</a> can be used profitably if the expressions are very short and obvious: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$title</span> <span class="o">=</span> <span class="nv">$page</span> <span class="o">?</span> <span class="nv">$page</span><span class="o">-&gt;</span><span class="na">getTitle</span><span class="p">()</span> <span class="o">:</span> <span class="nx">Title</span><span class="o">::</span><span class="na">newMainPage</span><span class="p">();</span> </pre></div> <p>But if you're considering a multi-line expression with a ternary operator, please consider using an <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">if</span>&#160;<span class="p">()</span></code> block instead. Remember, disk space is cheap, code readability is everything, "if" is English and "<code>?:</code>" is not. If you are using a multi-line ternary expression, the question mark and colon should go at the beginning of the second and third lines and not the end of the first and second (in contrast to MediaWiki's JavaScript convention). </p><p>Since MediaWiki requires PHP 8.1.0 or later, use of the <a rel="nofollow" class="external text" href="https://php.net/control-structures.if#102060">shorthand ternary operator</a> (<code>?:</code>) also known as the <a href="https://en.wikipedia.org/wiki/Elvis_operator" class="extiw" title="w:Elvis operator">elvis operator</a>, introduced in PHP 5.3, is allowed. </p><p>Since PHP 7.0 the <a rel="nofollow" class="external text" href="https://php.net/migration70.new-features">null coalescing operator</a> is also available and can replace the ternary operator in some use cases. </p><p> For example, instead of </p><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$wiki</span> <span class="o">=</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">mParams</span><span class="p">[</span><span class="s1">&#39;wiki&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="o">?</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">mParams</span><span class="p">[</span><span class="s1">&#39;wiki&#39;</span><span class="p">]</span> <span class="o">:</span> <span class="k">false</span><span class="p">;</span> </pre></div><p> you could instead write the following: </p><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$wiki</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">mParams</span><span class="p">[</span><span class="s1">&#39;wiki&#39;</span><span class="p">]</span> <span class="o">??</span> <span class="k">false</span><span class="p">;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="String_literals">String literals</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=4" title="Edit section: String literals"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Single quotes are preferred in all cases where they are equivalent to double quotes. Code using single quotes is less error-prone and easier to review, as it cannot accidentally contain <a rel="nofollow" class="external text" href="https://php.net/language.types.string#language.types.string.syntax.double">escape sequences</a> or <a rel="nofollow" class="external text" href="https://php.net/language.types.string#language.types.string.parsing">variables</a>. For example, the regular expression <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;/</span><span class="se">\\</span><span class="s2">n+/&quot;</span></code> requires an extra backslash, making it slightly more confusing and error-prone than <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="s1">&#39;/\n+/&#39;</span></code>. Also for people using US/UK qwerty keyboards, they are easier to type, since it avoids the need to press shift. </p><p>However, do not be afraid of using PHP's double-quoted string interpolation feature: <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$elementId</span> <span class="o">=</span> <span class="s2">&quot;myextension-</span><span class="si">$index</span><span class="s2">&quot;</span><span class="p">;</span></code> This has slightly better performance characteristics than the equivalent using the concatenation (dot) operator, and it looks nicer too. </p><p>Heredoc-style strings are sometimes useful: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$s</span> <span class="o">=</span> <span class="s">&lt;&lt;&lt;</span><span class="dl">EOT</span> <span class="s">&lt;div class=&quot;mw-some-class&quot;&gt;</span> <span class="s">$boxContents</span> <span class="s">&lt;/div&gt;</span> <span class="dl">EOT</span><span class="p">;</span> </pre></div> <p>Some authors like to use END as the ending token, which is also the name of a PHP function. </p> <div class="mw-heading mw-heading3"><h3 id="Functions_and_parameters">Functions and parameters</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=5" title="Edit section: Functions and parameters"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Avoid passing huge numbers of parameters to functions or constructors: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// Constructor for Block.php from 1.17 to 1.26. DO NOT do this!</span> <span class="k">function</span> <span class="fm">__construct</span><span class="p">(</span> <span class="nv">$address</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="nv">$user</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$by</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$reason</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="nv">$timestamp</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$auto</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$expiry</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="nv">$anonOnly</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$createAccount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$enableAutoblock</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$hideName</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$blockEmail</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">$allowUsertalk</span> <span class="o">=</span> <span class="mi">0</span> <span class="p">)</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span> </pre></div> <p>It quickly becomes impossible to remember the order of parameters, and you will inevitably end up having to hardcode all the defaults in callers just to customise a parameter at the end of the list. If you are tempted to code a function like this, consider passing an associative array of named parameters instead. </p><p>In general, using boolean parameters is discouraged in functions. In <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$object</span><span class="o">-&gt;</span><span class="na">getSomething</span><span class="p">(</span> <span class="nv">$input</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span> <span class="p">)</span></code>, without looking up the documentation for <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">MyClass</span><span class="o">::</span><span class="na">getSomething</span><span class="p">()</span></code>, it is impossible to know what those parameters are meant to indicate. Much better is to either use class constants, and make a generic flag parameter: </p> <dl><dd><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$myResult</span> <span class="o">=</span> <span class="nx">MyClass</span><span class="o">::</span><span class="na">getSomething</span><span class="p">(</span> <span class="nv">$input</span><span class="p">,</span> <span class="nx">MyClass</span><span class="o">::</span><span class="na">FROM_DB</span> <span class="o">|</span> <span class="nx">MyClass</span><span class="o">::</span><span class="na">PUBLIC_ONLY</span> <span class="p">);</span> </pre></div></dd></dl> <p>Or to make your function accept an array of named parameters: </p> <dl><dd><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$myResult</span> <span class="o">=</span> <span class="nx">MyClass</span><span class="o">::</span><span class="na">getSomething</span><span class="p">(</span> <span class="nv">$input</span><span class="p">,</span> <span class="p">[</span> <span class="s1">&#39;fromDB&#39;</span><span class="p">,</span> <span class="s1">&#39;publicOnly&#39;</span> <span class="p">]</span> <span class="p">);</span> </pre></div></dd></dl> <p>Try <a href="https://lists.wikimedia.org/hyperkitty/list/wikitech-l@lists.wikimedia.org/thread/BDCF72TDVMWPNAZL6RASFJIOHLUGFQUD/" class="extiw" title="listarchive:list/wikitech-l@lists.wikimedia.org/thread/BDCF72TDVMWPNAZL6RASFJIOHLUGFQUD/">not to repurpose variables</a> over the course of a function, and avoid modifying the parameters passed to a function (unless they're passed by reference and that's the whole point of the function, obviously). </p> <div class="mw-heading mw-heading3"><h3 id="Assignment_expressions">Assignment expressions</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=6" title="Edit section: Assignment expressions"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Using assignment as an expression is surprising to the reader and looks like an error. Do not write code like this: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">if</span> <span class="p">(</span> <span class="nv">$a</span> <span class="o">=</span> <span class="nx">foo</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span> <span class="nx">bar</span><span class="p">();</span> <span class="p">}</span> </pre></div> <p>Space is cheap, and you're a fast typist, so instead use: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$a</span> <span class="o">=</span> <span class="nx">foo</span><span class="p">();</span> <span class="k">if</span> <span class="p">(</span> <span class="nv">$a</span> <span class="p">)</span> <span class="p">{</span> <span class="nx">bar</span><span class="p">();</span> <span class="p">}</span> </pre></div> <p>Using assignment in a <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">while</span><span class="p">()</span></code> clause used to be legitimate, for iteration: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$res</span> <span class="o">=</span> <span class="nv">$dbr</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span> <span class="s1">&#39;SELECT foo, bar FROM some_table&#39;</span> <span class="p">);</span> <span class="k">while</span> <span class="p">(</span> <span class="nv">$row</span> <span class="o">=</span> <span class="nv">$dbr</span><span class="o">-&gt;</span><span class="na">fetchObject</span><span class="p">(</span> <span class="nv">$res</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span> <span class="nx">showRow</span><span class="p">(</span> <span class="nv">$row</span> <span class="p">);</span> <span class="p">}</span> </pre></div> <p>This is unnecessary in new code; instead use: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">$res</span> <span class="o">=</span> <span class="nv">$dbr</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span> <span class="s1">&#39;SELECT foo, bar FROM some_table&#39;</span> <span class="p">);</span> <span class="k">foreach</span> <span class="p">(</span> <span class="nv">$res</span> <span class="k">as</span> <span class="nv">$row</span> <span class="p">)</span> <span class="p">{</span> <span class="nx">showRow</span><span class="p">(</span> <span class="nv">$row</span> <span class="p">);</span> <span class="p">}</span> </pre></div> <p><br /> </p> <div class="mw-heading mw-heading3"><h3 id="C_borrowings">C borrowings</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=7" title="Edit section: C borrowings"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The PHP language was designed by people who love C and wanted to bring souvenirs from that language into PHP. But PHP has some important differences from C. </p><p>In C, constants are implemented as preprocessor macros and are fast. In PHP, they are implemented by doing a runtime hashtable lookup for the constant name, and are slower than just using a string literal. In most places where you would use an enum or enum-like set of macros in C, you can use string literals in PHP. </p><p>PHP has three special literals for which upper-/lower-/mixed-case is insignificant in the language (since PHP 5.1.3), but for which our convention is always lowercase: <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">true</span></code>, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">false</span></code> and <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">null</span></code>. </p><p>Use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">elseif</span></code> not <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">else</span> <span class="k">if</span></code>. They have <a rel="nofollow" class="external text" href="https://php.net/elseif">subtly different meanings</a>: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// This:</span> <span class="k">if</span> <span class="p">(</span> <span class="nv">$foo</span> <span class="o">===</span> <span class="s1">&#39;bar&#39;</span> <span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Hello world&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span> <span class="nv">$foo</span> <span class="o">===</span> <span class="s1">&#39;Bar&#39;</span> <span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Hello world&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span> <span class="nv">$baz</span> <span class="o">===</span> <span class="nv">$foo</span> <span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Hello baz&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Eh?&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// Is actually equivalent to:</span> <span class="k">if</span> <span class="p">(</span> <span class="nv">$foo</span> <span class="o">===</span> <span class="s1">&#39;bar&#39;</span> <span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Hello world&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span> <span class="nv">$foo</span> <span class="o">==</span> <span class="s1">&#39;Bar&#39;</span> <span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Hello world&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span> <span class="nv">$baz</span> <span class="o">==</span> <span class="nv">$foo</span> <span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Hello baz&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;Eh?&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <p>And the latter has poorer performance. </p> <div class="mw-heading mw-heading3"><h3 id="Alternative_syntax_for_control_structures">Alternative syntax for control structures</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=8" title="Edit section: Alternative syntax for control structures"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>PHP offers an alternative syntax for control structures using colons and keywords such as <code>endif</code>, <code>endwhile</code>, <i>etc.</i>: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">if</span> <span class="p">(</span> <span class="nv">$foo</span> <span class="o">==</span> <span class="nv">$bar</span> <span class="p">)</span><span class="o">:</span> <span class="k">echo</span> <span class="s2">&quot;&lt;div&gt;Hello world&lt;/div&gt;&quot;</span><span class="p">;</span> <span class="k">endif</span><span class="p">;</span> </pre></div> <p>This syntax should be avoided, as it prevents many text editors from automatically matching and folding braces. Braces should be used instead: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">if</span> <span class="p">(</span> <span class="nv">$foo</span> <span class="o">==</span> <span class="nv">$bar</span> <span class="p">)</span> <span class="p">{</span> <span class="k">echo</span> <span class="s2">&quot;&lt;div&gt;Hello world&lt;/div&gt;&quot;</span><span class="p">;</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Brace_placement">Brace placement</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=9" title="Edit section: Brace placement"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>See <a href="/wiki/Special:MyLanguage/Manual:Coding_conventions#Indenting_and_alignment" title="Special:MyLanguage/Manual:Coding conventions">Manual:Coding conventions#Indenting and alignment</a>. </p><p>For <a rel="nofollow" class="external text" href="https://www.php.net/functions.anonymous">anonymous functions</a>, prefer <a rel="nofollow" class="external text" href="https://www.php.net/functions.arrow">arrow functions</a> when the anonymous function consists only of one line. Arrow functions are more concise and readable than regular anonymous functions and neatly side-steps formatting issues that arise with single-line anonymous functions.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Type_declarations_in_function_parameters">Type declarations in function parameters</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=10" title="Edit section: Type declarations in function parameters"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Use <a rel="nofollow" class="external text" href="https://www.php.net/language.types.declarations">type declarations</a> and <a rel="nofollow" class="external text" href="https://www.php.net/language.types.declarations#example-80">return type declarations</a> (type hinting) when applicable. (But see <a href="#Don&#39;t_add_type_declarations_for_&quot;big&quot;_legacy_classes">#Don't add type declarations for "big" legacy classes</a> below.) </p><p>Scalar typehints are allowed as of MediaWiki 1.35, following the switch to PHP 7.2 (<a href="https://phabricator.wikimedia.org/T231710" class="extiw" title="phab:T231710">T231710</a>). </p><p>Use PHP 7.1 syntax for nullable parameters: choose </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">public</span> <span class="k">function</span> <span class="nf">foo</span> <span class="p">(</span> <span class="o">?</span><span class="nx">MyClass</span> <span class="nv">$mc</span> <span class="p">)</span> <span class="p">{}</span> </pre></div> <p>instead of </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">public</span> <span class="k">function</span> <span class="nf">foo</span> <span class="p">(</span> <span class="nx">MyClass</span> <span class="nv">$mc</span> <span class="o">=</span> <span class="k">null</span> <span class="p">)</span> <span class="p">{}</span> </pre></div> <p>The former conveys precisely the nullability of a parameter, without risking any ambiguity with optional parameters. IDEs and static analysis tools will also recognize it as such, and will not complain if a non-nullable parameter follows a nullable one. </p><p><br /> </p> <div class="mw-heading mw-heading2"><h2 id="Naming">Naming</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=11" title="Edit section: Naming"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <table class="wikitable"> <tbody><tr> <th>Files </th> <td>UpperCamelCase </td> <td>PHP files should be named after the class they contain, which is UpperCamelCase. For instance, <code>WebRequest.php</code> contains the <code>WebRequest</code> class. See also <a href="/wiki/Special:MyLanguage/Manual:Coding_conventions#File_naming" title="Special:MyLanguage/Manual:Coding conventions">Manual:Coding conventions</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions#File_naming" title="Manual:Coding conventions"> </a></span>. </td></tr> <tr> <th>Namespaces </th> <td>UpperCamelCase </td> <td> </td></tr> <tr> <th>Classes </th> <td>UpperCamelCase </td> <td>Use <a href="https://en.wikipedia.org/wiki/CamelCase" class="extiw" title="w:CamelCase">UpperCamelCase</a> when naming classes. For example: <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">class</span> <span class="nc">ImportantClass</span></code> </td></tr> <tr> <th>Constants </th> <td>Uppercase with underscores </td> <td>Use uppercase with underscores for global and class constants: <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">DB_PRIMARY</span></code>, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">IDBAccessObject</span><span class="o">::</span><span class="na">READ_LATEST</span></code>. </td></tr> <tr> <th>Functions </th> <td>lowerCamelCase </td> <td>Use <a href="https://en.wikipedia.org/wiki/CamelCase" class="extiw" title="w:CamelCase">lowerCamelCase</a> when naming functions. For example: <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">private</span> <span class="k">function</span> <span class="nf">doSomething</span><span class="p">(</span> <span class="nv">$userPrefs</span><span class="p">,</span> <span class="nv">$editSummary</span> <span class="p">)</span> </pre></div> </td></tr> <tr> <th>Function variables </th> <td>lowerCamelCase </td> <td>Use <a href="https://en.wikipedia.org/wiki/CamelCase" class="extiw" title="w:CamelCase">lowerCamelCase</a> when naming function variables. Avoid using underscores in variable names. </td></tr></tbody></table> <div class="mw-heading mw-heading3"><h3 id="Prefixes">Prefixes</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=12" title="Edit section: Prefixes"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>There are also some prefixes that can be used in different places: </p><p><span class="anchor" id="Functions"></span> </p> <div class="mw-heading mw-heading4"><h4 id="Function_names">Function names</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=13" title="Edit section: Function names"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><code>wf</code> (wiki functions) – top-level functions, <i>e.g.</i> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">function</span> <span class="nf">wfFuncname</span><span class="p">()</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span> </pre></div></li> <li><code>ef</code> (extension functions) = global functions in extensions, although "in most cases modern style puts hook functions as static methods on a class, leaving few or no raw top-level functions to be so named." (-- brion in <a href="/wiki/Manual_talk:Coding_conventions#ef_prefix_9510" title="Manual talk:Coding conventions">Manual_talk:Coding_conventions#ef_prefix_9510</a>)</li></ul> <p>Verb phrases are preferred: use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">getReturnText</span><span class="p">()</span></code> instead of <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">returnText</span><span class="p">()</span></code>. When exposing functions for use in testing, mark these as <code>@internal</code> per the <a href="/wiki/Special:MyLanguage/Stable_interface_policy" title="Special:MyLanguage/Stable interface policy">Stable interface policy</a>. Misuse or unofficial reliance on these is more problematic than most internal methods, and as such we tend to make these throw if they run outside of a test environment. </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="sd">/**</span> <span class="sd"> * Reset example data cache.</span> <span class="sd"> *</span> <span class="sd"> * @internal For testing only</span> <span class="sd"> */</span> <span class="k">public</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">clearCacheForTest</span><span class="p">()</span><span class="o">:</span> <span class="nx">void</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nb">defined</span><span class="p">(</span> <span class="s1">&#39;MW_PHPUNIT_TEST&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span> <span class="k">throw</span> <span class="k">new</span> <span class="nx">RuntimeException</span><span class="p">(</span> <span class="s1">&#39;Not allowed outside tests&#39;</span> <span class="p">);</span> <span class="p">}</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$exampleDataCache</span> <span class="o">=</span> <span class="p">[];</span> <span class="p">}</span> </pre></div> <p><span class="anchor" id="Variables"></span> </p> <div class="mw-heading mw-heading4"><h4 id="Variable_names">Variable names</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=14" title="Edit section: Variable names"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><code><a href="/wiki/Special:MyLanguage/Manual:Wg_variable" title="Special:MyLanguage/Manual:Wg variable">$wg</a></code> – global variables, <i>e.g.</i><code><a href="/wiki/Special:MyLanguage/Manual:$wgTitle" title="Special:MyLanguage/Manual:$wgTitle">$wgTitle</a><span style="display:none"><a href="/wiki/Manual:$wgTitle" title="Manual:$wgTitle"> </a></span></code>. Always use this for new globals, so that it's easy to spot missing "<code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">global</span> <span class="nv">$wgFoo</span></code>" declarations. In extensions, the extension name should be used as a namespace delimiter. For example, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$wgAbuseFilterConditionLimit</span></code>, <b>not</b> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$wgConditionLimit</span></code>.</li> <li>Global declarations should be at the beginning of a function so dependencies can be determined without having to read the whole function.</li></ul> <p>It is common to work with an instance of the <code>Database</code> class; we have a naming convention for these which helps keep track of the nature of the server to which we are connected. This is of particular importance in replicated environments, such as Wikimedia and other large wikis; in development environments, there is usually no difference between the two types, which can conceal subtle errors. </p> <ul><li><code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$dbw</span></code> – a <code>Database</code> object for writing (a primary connection)</li> <li><code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$dbr</span></code> – a <code>Database</code> object for non-concurrency-sensitive reading (this may be a read-only replica, slightly behind primary state, so don't ever try to write to the database with it, or get an "authoritative" answer to important queries like permissions and block status)</li></ul> <p>The following may be seen in old code but are discouraged in new code: </p> <ul><li><code>$ws</code> – Session variables, <i>e.g.</i> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">&#39;wsSessionName&#39;</span><span class="p">]</span></code></li> <li><code>$wc</code> – Cookie variables, <i>e.g.</i> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$_COOKIE</span><span class="p">[</span><span class="s1">&#39;wcCookieName&#39;</span><span class="p">]</span></code></li> <li><code>$wp</code> – Post variables (submitted via form fields), <i>e.g.</i> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$wgRequest</span><span class="o">-&gt;</span><span class="na">getText</span><span class="p">(</span> <span class="s1">&#39;wpLoginName&#39;</span> <span class="p">)</span></code></li> <li><code>$m</code> – object member variables: <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">mPage</span></code>. This is <b>discouraged in new code</b>, but try to stay consistent within a class.</li></ul> <p><br /> </p> <div class="mw-heading mw-heading2"><h2 id="Pitfalls">Pitfalls</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=15" title="Edit section: Pitfalls"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="empty()"><span id="empty.28.29"></span><span class="anchor" id="empty"></span> <code>empty()</code></h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=16" title="Edit section: empty()"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The <a rel="nofollow" class="external text" href="https://php.net/empty">empty()</a> function should only be used when you want to suppress errors. Otherwise just use <code>!</code> (boolean conversion). </p> <ul><li><code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">empty</span><span class="p">(</span> <span class="nv">$var</span> <span class="p">)</span></code> essentially does <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="o">!</span><span class="nb">isset</span><span class="p">(</span> <span class="nv">$var</span> <span class="p">)</span> <span class="o">||</span> <span class="o">!</span><span class="nv">$var</span></code>.<br />Common use case: Optional boolean configuration keys that default to <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">false</span></code>. <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">enableFoo</span> <span class="o">=</span> <span class="o">!</span><span class="k">empty</span><span class="p">(</span> <span class="nv">$options</span><span class="p">[</span><span class="s1">&#39;foo&#39;</span><span class="p">]</span> <span class="p">);</span></code></li> <li>Beware of <a href="#Boolean_conversion">boolean conversion pitfalls</a>.</li> <li>It suppresses errors about undefined properties and variables. If only intending to test for undefined, use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="o">!</span><span class="nb">isset</span><span class="p">()</span></code>. If only intending to test for "empty" values (<i>e.g.</i> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">false</span></code>, 0, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="p">[]</span></code>, <i>etc.</i>), use <code>!</code>.</li></ul> <div class="mw-heading mw-heading3"><h3 id="isset()"><span id="isset.28.29"></span><span class="anchor" id="isset"></span> <code>isset()</code></h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=17" title="Edit section: isset()"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Do not use <a rel="nofollow" class="external text" href="https://php.net/isset">isset()</a> to test for <code>null</code>. Using <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nb">isset</span></code> in this situation could introduce errors by hiding misspelled variable names. Instead, use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$var</span> <span class="o">===</span> <span class="k">null</span></code>. </p> <div class="mw-heading mw-heading3"><h3 id="Boolean_conversion">Boolean conversion</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=18" title="Edit section: Boolean conversion"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nv">$var</span> <span class="p">)</span> <span class="p">{</span> <span class="nx">…</span> <span class="p">}</span> </pre></div> <ul><li>Do not use <code>!</code> or <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">empty</span></code> to test if a string or array is empty, because PHP considers <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="s1">&#39;0&#39;</span></code> to be falsy – but <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="s1">&#39;0&#39;</span></code> is a valid title and valid user name in MediaWiki. Use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><span class="o">===</span> <span class="s1">&#39;&#39;</span></code> or <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><span class="o">===</span> <span class="p">[]</span></code> instead.</li> <li>Study the rules for <a rel="nofollow" class="external text" href="https://php.net/language.types.boolean#language.types.boolean.casting">conversion to boolean</a>. Be careful when converting strings to boolean.</li></ul> <div class="mw-heading mw-heading3"><h3 id="Other">Other</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=19" title="Edit section: Other"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a rel="nofollow" class="external text" href="https://php.net/operators.array">Array plus</a> does not renumber the keys of numerically-indexed arrays, so <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="p">[</span> <span class="s1">&#39;a&#39;</span> <span class="p">]</span> <span class="o">+</span> <span class="p">[</span> <span class="s1">&#39;b&#39;</span> <span class="p">]</span> <span class="o">===</span> <span class="p">[</span> <span class="s1">&#39;a&#39;</span> <span class="p">]</span></code>. If you want keys to be renumbered, use <a rel="nofollow" class="external text" href="https://php.net/array_merge">array_merge()</a>: <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nb">array_merge</span><span class="p">(</span> <span class="p">[</span> <span class="s1">&#39;a&#39;</span> <span class="p">],</span> <span class="p">[</span> <span class="s1">&#39;b&#39;</span> <span class="p">]</span> <span class="p">)</span> <span class="o">===</span> <span class="p">[</span> <span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span> <span class="p">]</span></code></li> <li>Make sure you have <a rel="nofollow" class="external text" href="https://php.net/error_reporting">error_reporting()</a> set to <code>-1</code>. This will notify you of undefined variables and other subtle gotchas that stock PHP will ignore. See also <a href="/wiki/Special:MyLanguage/Manual:How_to_debug" title="Special:MyLanguage/Manual:How to debug">Manual:How to debug</a><span style="display:none"><a href="/wiki/Manual:How_to_debug" title="Manual:How to debug"> </a></span>.</li> <li>When working in a pure PHP file (<i>e.g.</i> not an HTML template), omit any trailing <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="cp">?&gt;</span></code> tags. These tags often cause issues with trailing white-space and "headers already sent" error messages (cf. <a href="https://bugzilla.wikimedia.org/show_bug.cgi?id=17642" class="extiw" title="bugzilla:17642">bugzilla:17642</a> and <a rel="nofollow" class="external free" href="http://news.php.net/php.general/280796">http://news.php.net/php.general/280796</a>). It is conventional in version control for files to have a new line at end-of-file (which editors may add automatically), which would then trigger this error.</li> <li>Do not use the <a rel="nofollow" class="external text" href="https://php.net/goto">goto()</a> syntax introduced in 5.3. PHP may have introduced the feature, but that does not mean we should use it.</li> <li>Do not pass by reference when traversing an array with <code>foreach</code> unless you <i>have to</i>. Even then, be aware of the consequences. (See <a rel="nofollow" class="external free" href="https://web.archive.org/web/20220924191559/https://www.intracto.com/en-be/blog/php-quirks-passing-an-array-by-reference/">https://web.archive.org/web/20220924191559/https://www.intracto.com/en-be/blog/php-quirks-passing-an-array-by-reference/</a> and the <a rel="nofollow" class="external text" href="https://www.php.net/control-structures.foreach">PHP manual</a>)</li> <li>PHP lets you declare static variables even within a non-static method of a class. This has led to subtle bugs in some cases, as the variables are shared between instances. Where you would not use a <code>private static</code> property, do not use a static variable either.</li></ul> <div class="mw-heading mw-heading3"><h3 id="Equality_operators">Equality operators</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=20" title="Edit section: Equality operators"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Be careful with <a rel="nofollow" class="external text" href="https://php.net/operators.comparison">double-equals comparison operators</a>. Triple-equals (<code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="o">===</span></code>) is generally more intuitive and should be preferred unless you have a reason to use double-equals (<code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="o">==</span></code>). </p> <ul><li><code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="s1">&#39;000&#39;</span> <span class="o">==</span> <span class="s1">&#39;0&#39;</span></code> is <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">true</span></code> (!)</li> <li><code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="s1">&#39;000&#39;</span> <span class="o">===</span> <span class="s1">&#39;0&#39;</span></code> is <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">false</span></code></li> <li>To check if two scalars that are supposed to be numeric are equal, use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="o">==</span></code>, <i>e.g.</i> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="mi">5</span> <span class="o">==</span> <span class="s2">&quot;5&quot;</span></code> is true.</li> <li>To check if two variables are both of type 'string' and are the same sequence of characters, use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="o">===</span></code>, <i>e.g.</i> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;1.e6&quot;</span> <span class="o">===</span> <span class="s2">&quot;1.0e6&quot;</span></code> is false.</li></ul> <p>Watch out for internal functions and constructs that use weak comparisons; for instance, provide the third parameter to <code>in_array</code>, and don't mix scalar types in <code>switch</code> constructs. </p><p>Do not use <a href="https://en.wikipedia.org/wiki/Yoda_conditions" class="extiw" title="w:Yoda conditions">Yoda conditionals</a>. </p> <div class="mw-heading mw-heading3"><h3 id="JSON_number_precision">JSON number precision</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=21" title="Edit section: JSON number precision"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>JSON uses JavaScript's type system, so all numbers are represented as <a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format" class="extiw" title="w:Double-precision floating-point format">64bit IEEE floating point numbers</a>. This means that numbers lose precision when getting bigger, to the point where some whole numbers become indistinguishable: Numbers beyond 2^52 will have a precision worse than ±0.5, so a large integer may end up changing to a different integer. To avoid this issue, represent potentially large integers as strings in JSON. </p> <div class="mw-heading mw-heading2"><h2 id="Dos_and_don'ts"><span id="Dos_and_don.27ts"></span>Dos and don'ts</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=22" title="Edit section: Dos and don&#039;ts"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="Don't_use_built_in_serialization"><span id="Don.27t_use_built_in_serialization"></span>Don't use built in serialization</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=23" title="Edit section: Don&#039;t use built in serialization"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>PHP's built in serialization mechanism (the <code>serialize()</code> and <code>unserialize()</code> functions) should not be used for data stored (or read from) outside of the current process. Use JSON based serialization instead (however, beware the <a href="#JSON_number_precision">pitfalls</a>). This is policy established by <a href="/wiki/Requests_for_Comment" class="mw-redirect" title="Requests for Comment">RFC</a> <a href="https://phabricator.wikimedia.org/T161647" class="extiw" title="phab:T161647">T161647</a>. </p><p>The reason is twofold: (1) data serialized with this mechanism cannot reliably be unserialized with a later version of the same class. And (2) crafted serialized data can be used to execute malicious code, posing a serious security risk. </p><p>Sometimes, your code will not control the serialization mechanism, but will be using some library or driver that uses it internally. In such cases, steps should be taken to mitigate risk. The first issue mentioned above can be mitigated by converting any data to arrays or plain anonymous objects before serialization. The second issue can perhaps be mitigated using the whitelisting feature PHP 7 introduces for unserialization. </p> <div class="mw-heading mw-heading3"><h3 id="Don't_add_type_declarations_for_&quot;big&quot;_legacy_classes"><span id="Don.27t_add_type_declarations_for_.22big.22_legacy_classes"></span>Don't add type declarations for "big" legacy classes</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=24" title="Edit section: Don&#039;t add type declarations for &quot;big&quot; legacy classes"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>MediaWiki contains some big classes that are going to be split up or replaced sooner or later. This will be done in a way that keeps code compatible for a transition period, but it can break extension code that expects the legacy classes in parameter types, return types, property types, or similar. For instance, a hook handler's <code>$title</code> parameter may be passed some kind of <code>MockTitleCompat</code> class instead of a real <code>Title</code>. </p><p>Such big legacy classes should therefore not be used in type hints, only in PHPDoc.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">&#91;</span>3<span class="cite-bracket">&#93;</span></a></sup> The classes include: </p> <ul><li><code>Title</code></li> <li><code>Article</code></li> <li><code>WikiPage</code></li> <li><code>User</code></li> <li><code>MediaWiki</code></li> <li><code>OutputPage</code></li> <li><code>WebRequest</code></li> <li><code>EditPage</code></li></ul> <div class="mw-heading mw-heading2"><h2 id="Comments_and_documentation">Comments and documentation</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=25" title="Edit section: Comments and documentation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>It is essential that your code be well documented so that other developers and bug fixers can easily navigate the logic of your code. New classes, methods, and member variables should include comments providing brief descriptions of their functionality (unless it is obvious), even if private. In addition, all new methods should document their parameters and return values. </p><p>We use the <a href="https://en.wikipedia.org/wiki/Doxygen" class="extiw" title="w:Doxygen">Doxygen</a> documentation style (it is very similar to <a href="https://en.wikipedia.org/wiki/PHPDoc" class="extiw" title="w:PHPDoc">PHPDoc</a> for the subset that we use) to produce auto-generated documentation from code comments (see <a href="/wiki/Special:MyLanguage/Manual:mwdocgen.php" title="Special:MyLanguage/Manual:mwdocgen.php">Manual:Mwdocgen.php</a><span style="display:none"><a href="/wiki/Manual:Mwdocgen.php" title="Manual:Mwdocgen.php"> </a></span>). Begin a block of Doxygen comments with <code>/**</code>, instead of the Qt-style formatting <code>/*!</code>. Doxygen structural commands start with <code>@<i>tagname</i></code>. (Use <code>@</code> rather than <code>\</code> as the escape character – both styles work in Doxygen, but for backwards and future compatibility MediaWiki has chosen the <code>@param</code> style.) They organize the generated documentation (using <code>@ingroup</code>) and identify authors (using <code>@author</code> tags). </p><p>They describe a function or method, the parameters it takes (using <code>@param</code>), and what the function returns (using <code>@return</code>). The format for parameters is: </p> <div class="mw-code">@param <i>type</i> $<i>paramName</i> <i>Description of parameter</i></div> <p>If a parameter can be of multiple types, separate them with the pipe '|' character, for example: </p> <div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre><span></span>@param string|Language|bool $lang Language for the ToC title, defaults to user language </pre></div> <p>Continue sentences belonging to an annotation on the next line, indented with one additional space. </p><p>For every public interface (method, class, variable, whatever) you add or change, provide a <code>@since <i>VERSION</i></code> tag, so people extending the code via this interface know they are breaking compatibility with older versions of the code. </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">class</span> <span class="nc">Foo</span> <span class="p">{</span> <span class="sd">/**</span> <span class="sd"> * @var array Description here</span> <span class="sd"> * @example [ &#39;foo&#39; =&gt; Bar, &#39;quux&#39; =&gt; Bar, .. ]</span> <span class="sd"> */</span> <span class="k">protected</span> <span class="nv">$bar</span><span class="p">;</span> <span class="sd">/**</span> <span class="sd"> * Description here, following by documentation of the parameters.</span> <span class="sd"> *</span> <span class="sd"> * Some example:</span> <span class="sd"> * @code</span> <span class="sd"> * ...</span> <span class="sd"> * @endcode</span> <span class="sd"> *</span> <span class="sd"> * @since 1.24</span> <span class="sd"> * @param FooContext $context context for decoding Foos</span> <span class="sd"> * @param array|string $options Optionally pass extra options. Either a string</span> <span class="sd"> * or an array of strings.</span> <span class="sd"> * @return Foo|null New instance of Foo or null if quuxification failed.</span> <span class="sd"> */</span> <span class="k">public</span> <span class="k">function</span> <span class="nf">makeQuuxificatedFoo</span><span class="p">(</span> <span class="nx">FooContext</span> <span class="nv">$context</span> <span class="o">=</span> <span class="k">null</span><span class="p">,</span> <span class="nv">$options</span> <span class="o">=</span> <span class="p">[]</span> <span class="p">)</span> <span class="p">{</span> <span class="cm">/* .. */</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <p>FIXME usually means something is bad or broken. TODO means that improvements are needed; it does not necessarily mean that the person adding the comment is going to do it. HACK means that a quick but inelegant, awkward or otherwise suboptimal solution to an immediate problem was made, and that eventually a more thorough rewrite of the code should be done. </p> <div class="mw-heading mw-heading3"><h3 id="Source_file_headers">Source file headers</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=26" title="Edit section: Source file headers"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In order to be compliant with most licenses you should have something similar to the following (specific to GPLv2 applications) at the top of every source file. </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="cp">&lt;?php</span> <span class="sd">/**</span> <span class="sd"> * This program is free software; you can redistribute it and/or modify</span> <span class="sd"> * it under the terms of the GNU General Public License as published by</span> <span class="sd"> * the Free Software Foundation; either version 2 of the License, or</span> <span class="sd"> * (at your option) any later version.</span> <span class="sd"> *</span> <span class="sd"> * This program is distributed in the hope that it will be useful,</span> <span class="sd"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <span class="sd"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <span class="sd"> * GNU General Public License for more details.</span> <span class="sd"> *</span> <span class="sd"> * You should have received a copy of the GNU General Public License along</span> <span class="sd"> * with this program; if not, write to the Free Software Foundation, Inc.,</span> <span class="sd"> * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</span> <span class="sd"> * http://www.gnu.org/copyleft/gpl.html</span> <span class="sd"> *</span> <span class="sd"> * @file</span> <span class="sd"> */</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Doxygen_tags">Doxygen tags</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=27" title="Edit section: Doxygen tags"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>We use the following annotations which Doxygen recognizes. Use them in this order, for consistency: </p><p>File level: </p> <ul><li>@file</li></ul> <p>Class, class member, or global member: </p> <ul><li>@todo</li> <li>@var</li> <li>@stable, @newable, @deprecated, @internal, @unstable, @private</li> <li>@see</li> <li>@since</li> <li>@ingroup</li> <li>@param</li> <li>@return</li> <li>@throws</li> <li>@author</li> <li>@copyright</li></ul> <p><br /> </p> <div class="mw-heading mw-heading3"><h3 id="Test_annotations">Test annotations</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=28" title="Edit section: Test annotations"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In tests, we use the following annotations among others. These aren't merely documentation, they mean something to <a href="/wiki/Special:MyLanguage/PHPUnit" title="Special:MyLanguage/PHPUnit">PHPUnit</a><span style="display:none"><a href="/wiki/PHPUnit" class="mw-redirect" title="PHPUnit"> </a></span> and affect test execution. </p> <ul><li>@depends</li> <li>@group</li> <li>@covers</li> <li>@dataProvider</li></ul> <div class="mw-heading mw-heading2"><h2 id="Integration">Integration</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=29" title="Edit section: Integration"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>There are a few pieces of code in the MediaWiki codebase which are intended to be standalone and easily portable to other applications. While some of these now exist as <a href="/wiki/Special:MyLanguage/Manual:Developing_libraries" title="Special:MyLanguage/Manual:Developing libraries">separate libraries</a>, others remain within the MediaWiki source tree (<i>e.g.</i> the files in <code>/includes/libs</code>). Apart from these, code should be integrated into the rest of the MediaWiki environment, and should allow other areas of the codebase to integrate with it in return. </p> <div class="mw-heading mw-heading2"><h2 id="Visibility">Visibility</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=30" title="Edit section: Visibility"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Mark code as <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">private</span></code> unless there is a reason to make it more visible. Don't just make everything protected (= public to subclasses) or public. </p> <div class="mw-heading mw-heading3"><h3 id="Global_objects">Global objects</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=31" title="Edit section: Global objects"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r6353907">.mw-parser-output .hatnote{font-style:italic;padding-bottom:0.4em;margin-bottom:0.4em;border-bottom:1px solid #ccc}.mw-parser-output .hatnote.no-border{border-bottom:none}</style><div role="note" class="hatnote relarticle mainarticle">Main page: <a href="/wiki/Special:MyLanguage/Manual:RequestContext.php" title="Special:MyLanguage/Manual:RequestContext.php">Manual:RequestContext.php</a><span style="display:none"><a href="/wiki/Manual:RequestContext.php" title="Manual:RequestContext.php"> </a></span></div> <p>Do not access the PHP superglobals <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$_GET</span></code>, <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$_POST</span></code>, etc, directly; <a href="https://lists.wikimedia.org/pipermail/wikitech-l/2007-February/030029.html" class="extiw" title="mailarchive:wikitech-l/2007-February/030029.html">use</a> <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$request</span><span class="o">-&gt;</span><span class="na">get</span><span class="o">*</span><span class="p">(</span> <span class="s1">&#39;param&#39;</span> <span class="p">)</span></code> instead; there are various functions depending on what type of value you want.You can get a <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">WebRequest</span></code> from the nearest <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">RequestContext</span></code>, or if absolutely necessary <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">RequestContext</span><span class="o">::</span><span class="na">getMain</span><span class="p">()</span></code>. Equally, do not access <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$_SERVER</span></code> directly; use <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$request</span><span class="o">-&gt;</span><span class="na">getIP</span><span class="p">()</span></code> if you want to get the IP address of the current user. </p> <div class="mw-heading mw-heading3"><h3 id="Static_methods">Static methods</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=32" title="Edit section: Static methods"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Code using static methods should be written so that all method calls inside a class use <a rel="nofollow" class="external text" href="https://php.net/language.oop5.late-static-bindings">Late Static Bindings</a>, which basically means that calls to overridable static methods are resolved in the same way as calls to overridable instance methods. Specifically: </p> <ul><li>When calling static methods that may be overridden by subclasses from inside the class, use <code>static::func()</code>. This will call the override methods defined in subclasses if they exist, just like <code>$this-&gt;func()</code> does for instance methods.</li> <li>When calling static methods that may not be overridden (especially private methods), use <code>self::func()</code>. This will only call the methods of the class where it is used and its parent classes.</li> <li>When calling a parent method from an override of a static method, use <code>parent::func()</code>.</li> <li><small>If you ever think you need to call a grandparent class's version of a static method, or a child class's, think about it again, and use <code>forward_static_call()</code> if you don't come up with any better ideas.</small></li></ul> <p>Do not write out the class name like <code>ClassName::func()</code> in the above cases, as that will cause all method calls inside that method to ignore overrides of that class's members in subclasses.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">&#91;</span>4<span class="cite-bracket">&#93;</span></a></sup> This is only a problem for static methods, it works like you'd expect in instance methods, but avoid that syntax in instance methods too to avoid confusion about what the call will do.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> </p><p>These complications are annoying. Best avoid static methods so that you don't have to think about this. </p> <div class="mw-heading mw-heading3"><h3 id="Calling_methods">Calling methods</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=33" title="Edit section: Calling methods"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>For clarity, the method call syntax should match the method type: </p> <ul><li>Calls to static methods from should always use <code>::</code>, even though PHP lets you use <code>-&gt;</code> sometimes.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">&#91;</span>6<span class="cite-bracket">&#93;</span></a></sup></li> <li>Calls to instance methods should always use <code>-&gt;</code>, even though PHP lets you use <code>::</code> sometimes.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> (<code>self::</code> and <code>parent::</code> may be used when needed.)</li></ul> <div class="mw-heading mw-heading3"><h3 id="Classes">Classes</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=34" title="Edit section: Classes"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Encapsulate your code in an object-oriented class, or add functionality to existing classes; do not add new global functions or variables. Try to be mindful of the distinction between 'backend' classes, which represent entities in the database (e.g. <code>User</code>, <code>Block</code>, <code>RevisionRecord</code>, etc.), and 'frontend' classes, which represent pages or interfaces visible to the user (<code>SpecialPage</code>, <code>Article</code>, <code>ChangesList</code>, <i>etc.</i>). Even if your code is not obviously object-oriented, you can put it in a static class (e.g. <code>IP</code> or <code>Html</code>). </p><p>As a holdover from PHP 4's lack of private class members and methods, older code will be marked with comments such as <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="sd">/** @private */</span></code> to indicate the intention; respect this as if it were enforced by the interpreter. </p><p><a href="https://lists.wikimedia.org/pipermail/wikitech-l/2007-February/029435.html" class="extiw" title="mailarchive:wikitech-l/2007-February/029435.html">Mark new code with proper visibility modifiers</a>, including <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="k">public</span></code> if appropriate, but <b>do not</b> add visibility to existing code without first checking, testing and refactoring as required. It's generally a good idea to avoid visibility changes unless you're making changes to the function which would break old uses of it anyway. </p><p><br /> </p> <div class="mw-heading mw-heading2"><h2 id="Error_handling">Error handling</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=35" title="Edit section: Error handling"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In general, you should not suppress PHP errors. The proper method of handling errors is to <i>actually handle the errors</i>. </p><p>For example, if you are thinking of using an error suppression operator to suppress an invalid array index warning, you should instead perform an <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nb">isset</span></code> check on the array index before trying to access it. When possible, <i>always</i> catch or naturally prevent PHP errors. </p><p>Only if there is a situation where you are expecting an unavoidable PHP warning, you may use PHP's <a rel="nofollow" class="external text" href="https://php.net/operators.errorcontrol"><code>@</code> operator</a>. This is for cases where: </p> <ol><li>It is impossible to anticipate the error that is about to occur; and</li> <li>You are planning on handling the error in an appropriate manner after it occurs.</li></ol> <p>We use PHPCS to warn against use of the at-operator. If you really need to use it, you'll also need to instruct PHPCS to make an exemption, like so: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged</span> <span class="nv">$content</span> <span class="o">=</span> <span class="o">@</span><span class="nb">file_get_contents</span><span class="p">(</span> <span class="nv">$path</span> <span class="p">);</span> </pre></div> <p>An example use case is opening a file with <code>fopen()</code>. You can try to predict the error by calling <code>file_exists()</code> and <code>is_readable()</code>, but unlike <code>isset()</code>, such file operations add significant overhead and make for unstable code. For example, the file may be deleted or changed between the check and the actual <code>fopen()</code> call (see <a href="https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use" class="extiw" title="w:Time-of-check to time-of-use">TOC/TOU</a>). </p><p>In this case, write the code to just try the main operation you need to do. Then handle the case of the file failing to open, by using the <code>@</code> operator to prevent PHP from being noisy, and then check the result afterwards. For <code>fopen()</code> and <code>filemtime()</code>, that means checking for a boolean false return, and then performing a fallback, or throw an exception. </p> <div class="mw-heading mw-heading3"><h3 id="AtEase">AtEase</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=36" title="Edit section: AtEase"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>For PHP 5 and earlier, MediaWiki developers discouraged use of the <code>@</code> operator due to it causing unlogged and unexplained fatal errors (<a href="https://www.mediawiki.org/wiki/Special:Code/MediaWiki/39789#c2650" class="extiw" title="rev:39789">r39789</a>). Instead, we used custom <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">AtEase</span><span class="o">::</span><span class="na">suppressWarnings</span><span class="p">()</span></code> and <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">AtEase</span><span class="o">::</span><span class="na">restoreWarnings</span><span class="p">()</span></code> methods from the <a href="/wiki/Special:MyLanguage/at-ease" title="Special:MyLanguage/at-ease">at-ease</a><span style="display:none"><a href="/wiki/At-ease" title="At-ease"> </a></span> library. The reason is that the at-operator caused PHP to not provide error messages or stack traces upon fatal errors. While the at-operator is mainly intended for non-fatal errors (not exceptions or fatals), if a fatal were to happen it would make for a very poor developer experience. </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">use</span> <span class="nx">Wikimedia\AtEase\AtEase</span><span class="p">;</span> <span class="nx">AtEase</span><span class="o">::</span><span class="na">suppressWarnings</span><span class="p">();</span> <span class="nv">$content</span> <span class="o">=</span> <span class="nb">file_get_contents</span><span class="p">(</span> <span class="nv">$path</span> <span class="p">);</span> <span class="nx">AtEase</span><span class="o">::</span><span class="na">restoreWarnings</span><span class="p">();</span> </pre></div> <p>In PHP 7, the exception handler was fixed (<a rel="nofollow" class="external text" href="https://3v4l.org/t8i9q">example</a>) to always provide such errors, including a stack trace, regardless of error suppression. In 2020, use of AtEase started a phase out, reinstating the at-operator. (<a href="https://phabricator.wikimedia.org/T253461" class="extiw" title="phab:T253461">T253461</a>) </p> <div class="mw-heading mw-heading2"><h2 id="Exception_handling">Exception handling</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=37" title="Edit section: Exception handling"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Exceptions can be checked (meaning callers are expected to catch them) or unchecked (meaning callers must not catch them). </p><p>Unchecked exceptions are commonly used for programming errors, such as invalid arguments passed to a function. These exceptions should generally use (either directly or by subclassing) the <a rel="nofollow" class="external text" href="https://www.php.net/spl.exceptions">SPL exception classes</a>, and must not be documented with <code>@throws</code> annotations. Nonetheless, the conditions that lead to these exceptions being thrown should be documented in prose in the doc comment when they're part of a method's contract (for example, a string argument that must not be empty, or an integer argument that must be non-negative). </p><p>Checked exceptions, on the other hand, must always be documented with <code>@throws</code> annotations. When calling a method that can throw a checked exception, said exception must either be caught, or documented in the caller's doc comment. Checked exceptions should generally use dedicated exception classes extending <code>Exception</code>. It's recommended not to use SPL exceptions as base classes for checked exceptions, so that correct usage of exception classes can be enforced with static code analyzers. </p><p>The base <code>Exception</code> class must never be thrown directly: use more specific exception classes instead. It can be used in a <code>catch</code> clause if the intention is to catch all possible exceptions, but <code>Throwable</code> is usually more correct for that purpose. </p><p>In legacy code it is relatively common to throw or subclass the <code>MWException</code> class. This class must be avoided in new code, as it does not provide any advantage, and could actually be confusing (<a href="https://phabricator.wikimedia.org/T86704" class="extiw" title="phab:T86704">T86704</a>). </p><p>When creating a new exception class, consider implementing <code><span class="plainlinks"><a class="external text" href="https://doc.wikimedia.org/mediawiki-libs-NormalizedException/master/interfaceWikimedia_1_1NormalizedException_1_1INormalizedException.html">INormalizedException</a></span></code> if the exception message contains variable parts, and <code><span class="plainlinks"><a class="external text" href="https://doc.wikimedia.org/mediawiki-core/master/php/interfaceILocalizedException.html">ILocalizedException</a></span></code> if the exception message is shown to users. </p> <div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=38" title="Edit section: See also"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a href="/wiki/Special:MyLanguage/Continuous_integration/PHP_CodeSniffer" title="Special:MyLanguage/Continuous integration/PHP CodeSniffer">Continuous integration/PHP CodeSniffer</a><span style="display:none"><a href="/wiki/Continuous_integration/PHP_CodeSniffer" title="Continuous integration/PHP CodeSniffer"> </a></span></li></ul> <div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Manual:Coding_conventions/PHP&amp;action=edit&amp;section=39" title="Edit section: Notes"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="reflist" style="list-style-type: decimal;"> <div class="mw-references-wrap"><ol class="references"> <li id="cite_note-1"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text"> <a href="https://phabricator.wikimedia.org/T154789#8403709" class="extiw" title="phab:T154789">T154789 Closure formatting is ugly</a></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><a href="#cite_ref-2">↑</a></span> <span class="reference-text"><a class="external free" href="https://phabricator.wikimedia.org/T240307#6191788">https://phabricator.wikimedia.org/T240307#6191788</a></span> </li> <li id="cite_note-3"><span class="mw-cite-backlink"><a href="#cite_ref-3">↑</a></span> <span class="reference-text"><a class="external free" href="https://phabricator.wikimedia.org/T354697">https://phabricator.wikimedia.org/T354697</a></span> </li> <li id="cite_note-4"><span class="mw-cite-backlink"><a href="#cite_ref-4">↑</a></span> <span class="reference-text"><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">class</span> <span class="nc">X</span> <span class="p">{</span> <span class="c1">// Print the name of the class on which the method was called</span> <span class="k">protected</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="k">echo</span> <span class="k">static</span><span class="o">::</span><span class="na">class</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// Test what happens when calling the method</span> <span class="k">public</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">test</span><span class="p">()</span> <span class="p">{</span> <span class="nx">A</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="nx">B</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="nx">C</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="p">}</span> <span class="p">}</span> <span class="k">class</span> <span class="nc">A</span> <span class="k">extends</span> <span class="nx">X</span> <span class="p">{</span> <span class="c1">// With no override for f(), this prints &quot;A&quot;</span> <span class="p">}</span> <span class="k">class</span> <span class="nc">B</span> <span class="k">extends</span> <span class="nx">X</span> <span class="p">{</span> <span class="c1">// With an override that calls the parent method using `parent`, this prints &quot;B&quot;</span> <span class="k">protected</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="k">parent</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="p">}</span> <span class="p">}</span> <span class="k">class</span> <span class="nc">C</span> <span class="k">extends</span> <span class="nx">X</span> <span class="p">{</span> <span class="c1">// With an override that calls the parent method using `X`, this prints &quot;X&quot; instead of &quot;C&quot;</span> <span class="k">protected</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="nx">X</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="p">}</span> <span class="p">}</span> <span class="nx">X</span><span class="o">::</span><span class="na">test</span><span class="p">();</span> </pre></div></span> </li> <li id="cite_note-5"><span class="mw-cite-backlink"><a href="#cite_ref-5">↑</a></span> <span class="reference-text"><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">class</span> <span class="nc">X</span> <span class="p">{</span> <span class="c1">// Print the name of the class on which the method was called</span> <span class="k">protected</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="k">echo</span> <span class="k">static</span><span class="o">::</span><span class="na">class</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// Test what happens when calling the method</span> <span class="k">public</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">test</span><span class="p">()</span> <span class="p">{</span> <span class="p">(</span> <span class="k">new</span> <span class="nx">A</span> <span class="p">)</span><span class="o">-&gt;</span><span class="na">f</span><span class="p">();</span> <span class="p">(</span> <span class="k">new</span> <span class="nx">B</span> <span class="p">)</span><span class="o">-&gt;</span><span class="na">f</span><span class="p">();</span> <span class="p">(</span> <span class="k">new</span> <span class="nx">C</span> <span class="p">)</span><span class="o">-&gt;</span><span class="na">f</span><span class="p">();</span> <span class="p">}</span> <span class="p">}</span> <span class="k">class</span> <span class="nc">A</span> <span class="k">extends</span> <span class="nx">X</span> <span class="p">{</span> <span class="c1">// With no override for f(), this prints &quot;A&quot;</span> <span class="p">}</span> <span class="k">class</span> <span class="nc">B</span> <span class="k">extends</span> <span class="nx">X</span> <span class="p">{</span> <span class="c1">// With an override that calls the parent method using `parent`, this prints &quot;B&quot;</span> <span class="k">protected</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="k">parent</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="p">}</span> <span class="p">}</span> <span class="k">class</span> <span class="nc">C</span> <span class="k">extends</span> <span class="nx">X</span> <span class="p">{</span> <span class="c1">// With an override that calls the parent method using `X`, this prints &quot;C&quot; </span> <span class="c1">// (when the method is not static).</span> <span class="k">protected</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="nx">X</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="c1">// discouraged</span> <span class="p">}</span> <span class="p">}</span> <span class="nx">X</span><span class="o">::</span><span class="na">test</span><span class="p">();</span> </pre></div></span> </li> <li id="cite_note-6"><span class="mw-cite-backlink"><a href="#cite_ref-6">↑</a></span> <span class="reference-text"><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">class</span> <span class="nc">A</span> <span class="p">{</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;f&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="p">}</span> <span class="nv">$a</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">A</span><span class="p">;</span> <span class="nx">A</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="nv">$a</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="c1">// works, but discouraged</span> <span class="nv">$a</span><span class="o">-&gt;</span><span class="na">f</span><span class="p">();</span> <span class="c1">// works, but discouraged</span> </pre></div></span> </li> <li id="cite_note-7"><span class="mw-cite-backlink"><a href="#cite_ref-7">↑</a></span> <span class="reference-text"><div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="k">class</span> <span class="nc">A</span> <span class="p">{</span> <span class="k">function</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span> <span class="k">echo</span> <span class="s1">&#39;f&#39;</span><span class="p">;</span> <span class="p">}</span> <span class="k">function</span> <span class="fm">__construct</span><span class="p">()</span> <span class="p">{</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">f</span><span class="p">();</span> <span class="nv">$this</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="c1">// works, but discouraged</span> <span class="k">static</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="c1">// works, but discouraged</span> <span class="nx">A</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="c1">// works, but discouraged</span> <span class="p">}</span> <span class="p">}</span> <span class="nv">$a</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">A</span><span class="p">;</span> <span class="nx">A</span><span class="o">::</span><span class="na">f</span><span class="p">();</span> <span class="c1">// works in PHP 7, doesn&#39;t work in PHP 8</span> </pre></div></span> </li> </ol></div></div> <div class="navbox-styles nomobile"><style data-mw-deduplicate="TemplateStyles:r6230902">.mw-parser-output .navbox{border:1px solid #aaa;box-sizing:border-box;width:100%;margin:auto;clear:both;font-size:88%;text-align:center;padding:1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox th,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{text-align:center;padding-left:1em;padding-right:1em}.mw-parser-output th.navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background:#fdfdfd}.mw-parser-output .navbox-list{border-color:#fdfdfd}.mw-parser-output .navbox th,.mw-parser-output .navbox-title{background:#eaeeff}.mw-parser-output .navbox-abovebelow,.mw-parser-output th.navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background:#ddddff}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background:#e6e6ff}.mw-parser-output .navbox-even{background:#f7f7f7}.mw-parser-output .navbox-odd{background:transparent}.mw-parser-output th.navbox-title1{border-left:2px solid #fdfdfd;width:100%}.mw-parser-output td.navbox-list1{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .hlist dd,.mw-parser-output .navbox .hlist dt,.mw-parser-output .navbox .hlist li{white-space:nowrap}.mw-parser-output .navbox .hlist dd dl,.mw-parser-output .navbox .hlist dt dl,.mw-parser-output .navbox .hlist li ol,.mw-parser-output .navbox .hlist li ul{white-space:normal}.mw-parser-output ol+.navbox-styles+.navbox,.mw-parser-output ul+.navbox-styles+.navbox{margin-top:0.5em}</style></div><div role="navigation" class="navbox" aria-labelledby="Development_guidelines" style="border: 1px solid #aaa; padding: 3px;;padding:3px"><table class="nowraplinks hlist navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r6387430">.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li,.mw-parser-output .hlist .mw-empty-elt{display:none}.mw-parser-output .hlist dt:after{content:": "}.mw-parser-output .hlist dd:after,.mw-parser-output .hlist li:after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child:after,.mw-parser-output .hlist dt:last-child:after,.mw-parser-output .hlist li:last-child:after{content:none}.mw-parser-output .hlist dd dd:first-child:before,.mw-parser-output .hlist dd dt:first-child:before,.mw-parser-output .hlist dd li:first-child:before,.mw-parser-output .hlist dt dd:first-child:before,.mw-parser-output .hlist dt dt:first-child:before,.mw-parser-output .hlist dt li:first-child:before,.mw-parser-output .hlist li dd:first-child:before,.mw-parser-output .hlist li dt:first-child:before,.mw-parser-output .hlist li li:first-child:before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child:after,.mw-parser-output .hlist dd dt:last-child:after,.mw-parser-output .hlist dd li:last-child:after,.mw-parser-output .hlist dt dd:last-child:after,.mw-parser-output .hlist dt dt:last-child:after,.mw-parser-output .hlist dt li:last-child:after,.mw-parser-output .hlist li dd:last-child:after,.mw-parser-output .hlist li dt:last-child:after,.mw-parser-output .hlist li li:last-child:after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li:before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child:before,.mw-parser-output .hlist dt ol>li:first-child:before,.mw-parser-output .hlist li ol>li:first-child:before{content:" ("counter(listitem)"\a0 "}</style><style data-mw-deduplicate="TemplateStyles:r4692751">.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar ul{display:inline;white-space:nowrap}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em;width:6em}</style><div class="plainlinks hlist navbar mini"><ul><li class="nv-view"><a href="/wiki/Template:Development_guidelines_navigation" title="Template:Development guidelines navigation"><abbr title="View this template" style=";;background:none transparent;border:none;box-shadow:none; padding:0;">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:Development_guidelines_navigation" title="Template talk:Development guidelines navigation"><abbr title="Discuss this template" style=";;background:none transparent;border:none;box-shadow:none; padding:0;">t</abbr></a></li><li class="nv-edit"><a class="external text" href="https://www.mediawiki.org/w/index.php?title=Template:Development_guidelines_navigation&amp;action=edit"><abbr title="Edit this template" style=";;background:none transparent;border:none;box-shadow:none; padding:0;">e</abbr></a></li></ul></div><div id="Development_guidelines" style="font-size:114%;margin:0 4em"><a href="/wiki/Special:MyLanguage/Development_guidelines" title="Special:MyLanguage/Development guidelines"><span style="font-weight: bold;">Development guidelines</span></a><span style="display:none"><a href="/wiki/Development_guidelines" title="Development guidelines"> </a></span></div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%">Policies</th><td class="navbox-list1 navbox-list navbox-odd" style="width:100%;padding:0px"><div style="padding:0em 0.25em"> <ul><li><a href="/wiki/Special:MyLanguage/Development_policy" title="Special:MyLanguage/Development policy">Development policy</a><span style="display:none"><a href="/wiki/Development_policy" title="Development policy"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Wikimedia_Engineering_Architecture_Principles" title="Special:MyLanguage/Wikimedia Engineering Architecture Principles">Architecture principles</a><span style="display:none"><a href="/wiki/Wikimedia_Engineering_Architecture_Principles" title="Wikimedia Engineering Architecture Principles"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Wikimedia_services_policy" title="Special:MyLanguage/Wikimedia services policy">Services policy</a><span style="display:none"><a href="/wiki/Wikimedia_services_policy" title="Wikimedia services policy"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Support_policy_for_PHP" title="Special:MyLanguage/Support policy for PHP">Support policy for PHP</a><span style="display:none"><a href="/wiki/Support_policy_for_PHP" title="Support policy for PHP"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Gerrit/Privilege_policy" title="Special:MyLanguage/Gerrit/Privilege policy">Gerrit/Privilege policy</a><span style="display:none"><a href="/wiki/Gerrit/Privilege_policy" title="Gerrit/Privilege policy"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Stable_interface_policy" title="Special:MyLanguage/Stable interface policy">Stable interface policy</a><span style="display:none"><a href="/wiki/Stable_interface_policy" title="Stable interface policy"> </a></span> <ul><li><a href="/wiki/Special:MyLanguage/Stable_interface_policy/Frontend" title="Special:MyLanguage/Stable interface policy/Frontend">Frontend</a><span style="display:none"><a href="/wiki/Stable_interface_policy/Frontend" title="Stable interface policy/Frontend"> </a></span></li></ul></li> <li><a href="/wiki/Special:MyLanguage/MediaWiki_database_policy" title="Special:MyLanguage/MediaWiki database policy">MediaWiki database policy</a><span style="display:none"><a href="/wiki/MediaWiki_database_policy" title="MediaWiki database policy"> </a></span></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">General guidelines</th><td class="navbox-list1 navbox-list navbox-even" style="width:100%;padding:0px"><div style="padding:0em 0.25em"> <ul><li><a href="/wiki/Special:MyLanguage/Security_for_developers" title="Special:MyLanguage/Security for developers">Security for developers</a><span style="display:none"><a href="/wiki/Security_for_developers" title="Security for developers"> </a></span></li> <li><a href="https://wikitech.wikimedia.org/wiki/Performance/Guides/Backend_performance_practices" class="extiw" title="wikitech:Performance/Guides/Backend performance practices">Performance guidelines</a></li> <li><a href="/wiki/Special:MyLanguage/Gerrit/Commit_message_guidelines" title="Special:MyLanguage/Gerrit/Commit message guidelines">Commit message guidelines</a><span style="display:none"><a href="/wiki/Gerrit/Commit_message_guidelines" title="Gerrit/Commit message guidelines"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Security_checklist_for_developers" title="Special:MyLanguage/Security checklist for developers">Security checklist for developers</a><span style="display:none"><a href="/wiki/Security_checklist_for_developers" title="Security checklist for developers"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Localisation" title="Special:MyLanguage/Localisation">Localisation</a><span style="display:none"><a href="/wiki/Localisation" title="Localisation"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Design/Living_style_guide" title="Special:MyLanguage/Design/Living style guide">Design style guide</a><span style="display:none"><a href="/wiki/Design/Living_style_guide" title="Design/Living style guide"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Documentation/Style_guide" title="Special:MyLanguage/Documentation/Style guide">Documentation/Style guide</a><span style="display:none"><a href="/wiki/Documentation/Style_guide" title="Documentation/Style guide"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Accessibility_guide_for_developers" title="Special:MyLanguage/Accessibility guide for developers">Accessibility guide for developers</a><span style="display:none"><a href="/wiki/Accessibility_guide_for_developers" title="Accessibility guide for developers"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Inclusive_language" title="Special:MyLanguage/Inclusive language">Inclusive language</a><span style="display:none"><a href="/wiki/Inclusive_language" title="Inclusive language"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Guidelines_for_a_healthy_code_review_culture" title="Special:MyLanguage/Guidelines for a healthy code review culture">Guidelines for a healthy code review culture</a><span style="display:none"><a href="/wiki/Guidelines_for_a_healthy_code_review_culture" title="Guidelines for a healthy code review culture"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Collaborative_programming" title="Special:MyLanguage/Collaborative programming">Collaborative programming</a><span style="display:none"><a href="/wiki/Collaborative_programming" title="Collaborative programming"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Best_practices_for_extensions" title="Special:MyLanguage/Best practices for extensions">Best practices for extensions</a><span style="display:none"><a href="/wiki/Best_practices_for_extensions" title="Best practices for extensions"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Pre-commit_checklist" title="Special:MyLanguage/Manual:Pre-commit checklist">Pre-commit checklist</a><span style="display:none"><a href="/wiki/Manual:Pre-commit_checklist" title="Manual:Pre-commit checklist"> </a></span></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Code conventions</th><td class="navbox-list1 navbox-list navbox-odd" style="width:100%;padding:0px"><div style="padding:0em 0.25em"> <ul><li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions#Code_structure" title="Special:MyLanguage/Manual:Coding conventions">All languages</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions#Code_structure" title="Manual:Coding conventions"> </a></span></li> <li><b><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/PHP" title="Special:MyLanguage/Manual:Coding conventions/PHP">PHP</a></b><span style="display:none"><a class="mw-selflink selflink"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:PHP_unit_testing/Writing_unit_tests#Test_conventions" title="Special:MyLanguage/Manual:PHP unit testing/Writing unit tests">PHPUnit</a><span style="display:none"><a href="/wiki/Manual:PHP_unit_testing/Writing_unit_tests#Test_conventions" title="Manual:PHP unit testing/Writing unit tests"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/JavaScript" title="Special:MyLanguage/Manual:Coding conventions/JavaScript">JavaScript</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/JavaScript" title="Manual:Coding conventions/JavaScript"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/CSS" title="Special:MyLanguage/Manual:Coding conventions/CSS">CSS</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/CSS" title="Manual:Coding conventions/CSS"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/Selenium" title="Special:MyLanguage/Manual:Coding conventions/Selenium">Selenium</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/Selenium" title="Manual:Coding conventions/Selenium"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/Lua" title="Special:MyLanguage/Manual:Coding conventions/Lua">Lua</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/Lua" title="Manual:Coding conventions/Lua"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/Python" title="Special:MyLanguage/Manual:Coding conventions/Python">Python</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/Python" title="Manual:Coding conventions/Python"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/Java" title="Special:MyLanguage/Manual:Coding conventions/Java">Java</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/Java" title="Manual:Coding conventions/Java"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/SVG" title="Special:MyLanguage/Manual:Coding conventions/SVG">SVG</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/SVG" title="Manual:Coding conventions/SVG"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/Vue" title="Special:MyLanguage/Manual:Coding conventions/Vue">Vue</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/Vue" title="Manual:Coding conventions/Vue"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/Database" title="Special:MyLanguage/Manual:Coding conventions/Database">Database schemas</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/Database" title="Manual:Coding conventions/Database"> </a></span></li> <li><a href="/wiki/Special:MyLanguage/Product_Analytics/Style_guide" title="Special:MyLanguage/Product Analytics/Style guide">Analytics (Python, R, SQL)</a><span style="display:none"><a href="/wiki/Product_Analytics/Style_guide" title="Product Analytics/Style guide"> </a></span></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">API client code</th><td class="navbox-list1 navbox-list navbox-even" style="width:100%;padding:0px"><div style="padding:0em 0.25em"> <ul><li><a href="/wiki/Special:MyLanguage/API:Client_code/Gold_standard" title="Special:MyLanguage/API:Client code/Gold standard">Standards for API client libraries</a><span style="display:none"><a href="/wiki/API:Client_code/Gold_standard" title="API:Client code/Gold standard"> </a></span></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Drafts</th><td class="navbox-list1 navbox-list navbox-odd" style="width:100%;padding:0px"><div style="padding:0em 0.25em"> <ul><li><i><a href="/wiki/Special:MyLanguage/Manual:Coding_conventions/Documentation" title="Special:MyLanguage/Manual:Coding conventions/Documentation">Code documentation</a><span style="display:none"><a href="/wiki/Manual:Coding_conventions/Documentation" title="Manual:Coding conventions/Documentation"> </a></span></i></li></ul> </div></td></tr></tbody></table></div> <!-- NewPP limit report Parsed by mw‐web.eqiad.main‐7c479b968‐vgfzc Cached time: 20241116001616 Cache expiry: 2592000 Reduced expiry: false Complications: [show‐toc] CPU time usage: 0.661 seconds Real time usage: 0.867 seconds Preprocessor visited node count: 8737/1000000 Post‐expand include size: 62491/2097152 bytes Template argument size: 15646/2097152 bytes Highest expansion depth: 16/100 Expensive parser function count: 164/500 Unstrip recursion depth: 1/20 Unstrip post‐expand size: 56034/5000000 bytes Lua time usage: 0.159/10.000 seconds Lua memory usage: 2012279/52428800 bytes Number of Wikibase entities loaded: 0/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 563.836 1 -total 44.76% 252.352 48 Template:Ll 42.88% 241.760 1 Template:Conventions_navigation 41.59% 234.490 1 Template:Navbox 16.06% 90.525 96 Template:Translatable 14.81% 83.511 73 Template:Phpi 13.51% 76.180 48 Template:Pagelang 13.48% 76.003 73 Template:Inline-code 8.73% 49.206 1 Template:Development_guideline 7.98% 44.984 1 Template:Mbox --> <!-- Saved in parser cache with key mediawikiwiki:pcache:idhash:75216-0!canonical and timestamp 20241116001616 and revision id 6854458. Rendering was triggered because: page-view --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://www.mediawiki.org/w/index.php?title=Manual:Coding_conventions/PHP&amp;oldid=6854458">https://www.mediawiki.org/w/index.php?title=Manual:Coding_conventions/PHP&amp;oldid=6854458</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Special:Categories" title="Special:Categories">Category</a>: <ul><li><a href="/wiki/Category:Development_guidelines" title="Category:Development guidelines">Development guidelines</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 15 November 2024, at 20:54.</li> <li id="footer-info-copyright">Text is available under the <a rel="nofollow" class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-ShareAlike License</a>; additional terms may apply. Text in <a class="external text" href="https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents">the Help: namespace</a> is available under the <a rel="nofollow" class="external text" href="https://creativecommons.org/publicdomain/zero/1.0/">Creative Commons CC0 License</a>. By using this site, you agree to the <a class="external text" href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use">Terms of Use</a> and <a class="external text" href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy Policy</a>.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Project:About">About mediawiki.org</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Project:General_disclaimer">Disclaimers</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/www.mediawiki.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//m.mediawiki.org/w/index.php?title=Manual:Coding_conventions/PHP&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-f69cdc8f6-mf4ts","wgBackendResponseTime":148,"wgPageParseReport":{"limitreport":{"cputime":"0.661","walltime":"0.867","ppvisitednodes":{"value":8737,"limit":1000000},"postexpandincludesize":{"value":62491,"limit":2097152},"templateargumentsize":{"value":15646,"limit":2097152},"expansiondepth":{"value":16,"limit":100},"expensivefunctioncount":{"value":164,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":56034,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 563.836 1 -total"," 44.76% 252.352 48 Template:Ll"," 42.88% 241.760 1 Template:Conventions_navigation"," 41.59% 234.490 1 Template:Navbox"," 16.06% 90.525 96 Template:Translatable"," 14.81% 83.511 73 Template:Phpi"," 13.51% 76.180 48 Template:Pagelang"," 13.48% 76.003 73 Template:Inline-code"," 8.73% 49.206 1 Template:Development_guideline"," 7.98% 44.984 1 Template:Mbox"]},"scribunto":{"limitreport-timeusage":{"value":"0.159","limit":"10.000"},"limitreport-memusage":{"value":2012279,"limit":52428800}},"cachereport":{"origin":"mw-web.eqiad.main-7c479b968-vgfzc","timestamp":"20241116001616","ttl":2592000,"transientcontent":false}}});});</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10