From fa02b4229c23bb2652049d4d715901a616b09495 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Mon, 2 Oct 2017 10:10:28 +0200
Subject: [PATCH] [!!!][TASK] Cleanup global debug functions

The global "xdebug()" function is removed, as it is a stub for "debug" nowadays.
This function exists since SVN days,  and no comment or change why this is
available.

Additionally, the global "debug()" function had 6 parameters - the last three
were not evaluated and thus, were removed.

Resolves: #82640
Releases: master
Change-Id: I3e583c06282842e3dcb14f4b68589fd706be2519
Reviewed-on: https://review.typo3.org/54256
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
---
 ...82640-Re-arrangingGlobalDebugFunctions.rst | 35 +++++++++++++++++++
 .../Resources/PHP/GlobalDebugFunctions.php    | 35 +++++++------------
 .../Php/FunctionCallMatcher.php               | 14 ++++++++
 3 files changed, 62 insertions(+), 22 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-82640-Re-arrangingGlobalDebugFunctions.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-82640-Re-arrangingGlobalDebugFunctions.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-82640-Re-arrangingGlobalDebugFunctions.rst
new file mode 100644
index 000000000000..dbffcacda8f4
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-82640-Re-arrangingGlobalDebugFunctions.rst
@@ -0,0 +1,35 @@
+.. include:: ../../Includes.txt
+
+======================================================
+Breaking: #82640 - Re-arranging global debug functions
+======================================================
+
+See :issue:`82640`
+
+Description
+===========
+
+The global function :php:`xdebug()` has been dropped in favor of using :php:`debug()`.
+
+The global function :php:`debug()` now only takes a maximum of three function arguments.
+
+
+Impact
+======
+
+Calling `xdebug()` globally will throw in a PHP fatal error.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation in a development environment using the global functions in an old-fashioned way.
+
+
+Migration
+=========
+
+Instead of `xdebug()` simply use `debug()` as an alias. Ensure that when calling `debug()` that a
+maximum of three arguments are handed over to the function.
+
+.. index:: PHP-API, FullyScanned
\ No newline at end of file
diff --git a/typo3/sysext/core/Resources/PHP/GlobalDebugFunctions.php b/typo3/sysext/core/Resources/PHP/GlobalDebugFunctions.php
index 0224fb3a6097..0b765820a240 100644
--- a/typo3/sysext/core/Resources/PHP/GlobalDebugFunctions.php
+++ b/typo3/sysext/core/Resources/PHP/GlobalDebugFunctions.php
@@ -1,24 +1,15 @@
 <?php
-    // Simple debug function which prints output immediately
-    function xdebug($var = '', $debugTitle = 'xdebug')
-    {
-        // If you wish to use the debug()-function, and it does not output something,
-        // please edit the IP mask in TYPO3_CONF_VARS
-        if (!\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
-            return;
-        }
-        \TYPO3\CMS\Core\Utility\DebugUtility::debug($var, $debugTitle);
-    }
-
-    // Debug function
-    function debug($variable = '', $name = '*variable*', $line = '*line*', $file = '*file*', $recursiveDepth = 3, $debugLevel = E_DEBUG)
-    {
-        // If you wish to use the debug()-function, and it does not output something,
-        // please edit the IP mask in TYPO3_CONF_VARS
-        if (!\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
-            return;
-        }
-        $title = $name === '*variable*' ? '' : $name;
-        $group = $line === '*line*' ? null : $line;
-        \TYPO3\CMS\Core\Utility\DebugUtility::debug($variable, $title, $group);
+// Short-hand debug function
+// If you wish to use the debug()-function, and it does not output something,
+// please edit the IP mask in TYPO3_CONF_VARS
+function debug($variable = '', $title = null, $group = null)
+{
+    if (!\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(
+        \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'),
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']
+    )
+    ) {
+        return;
     }
+    \TYPO3\CMS\Core\Utility\DebugUtility::debug($variable, $title, $group);
+}
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/FunctionCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/FunctionCallMatcher.php
index 063657fd6510..3b8dd14c9219 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/FunctionCallMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/FunctionCallMatcher.php
@@ -15,4 +15,18 @@ return [
             'Breaking-37180-RemovedExtDirectDebugAndGLOBALSerror.rst',
         ],
     ],
+    'xdebug' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Breaking-82640-Re-arrangingGlobalDebugFunctions.rst',
+        ],
+    ],
+    'debug' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 3,
+        'restFiles' => [
+            'Breaking-82640-Re-arrangingGlobalDebugFunctions.rst',
+        ],
+    ],
 ];
-- 
GitLab