From: Renan Rodrigo <rr@ubuntu.com>
Date: Tue, 17 Feb 2026 23:12:24 -0300
Subject: Fix FTBFS with PHP8.5.

Throw proper Exceptions on errors.  E_USER_ERROR has been deprecated
since PHP8.4.

Bug-Debian: https://bugs.debian.org/1128313
---
 Console/CommandLine.php                           | 16 +++++--------
 Console/CommandLine/Argument.php                  |  8 +++----
 Console/CommandLine/Option.php                    | 28 +++++++++++------------
 Console/CommandLine/XmlParser.php                 |  8 +++----
 tests/console_commandline_addargument.phpt        |  2 +-
 tests/console_commandline_addargument_2.phpt      |  2 +-
 tests/console_commandline_addoption_errors_1.phpt |  2 +-
 tests/console_commandline_addoption_errors_2.phpt |  2 +-
 tests/console_commandline_addoption_errors_3.phpt |  2 +-
 tests/console_commandline_addoption_errors_4.phpt |  2 +-
 tests/console_commandline_addoption_errors_5.phpt |  2 +-
 tests/console_commandline_addoption_errors_6.phpt |  2 +-
 tests/console_commandline_addoption_errors_7.phpt |  2 +-
 tests/console_commandline_fromxmlfile_error.phpt  |  2 +-
 14 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/Console/CommandLine.php b/Console/CommandLine.php
index e7f83ab..c51590d 100644
--- a/Console/CommandLine.php
+++ b/Console/CommandLine.php
@@ -826,8 +826,7 @@ class Console_CommandLine
     {
         if (!isset(self::$actions[$name])) {
             if (!class_exists($class)) {
-                self::triggerError('action_class_does_not_exists',
-                    E_USER_ERROR,
+                self::throwException('action_class_does_not_exists',
                     array('{$name}' => $name, '{$class}' => $class));
             }
             self::$actions[$name] = array($class, false);
@@ -835,27 +834,24 @@ class Console_CommandLine
     }
 
     // }}}
-    // triggerError() {{{
+    // throwException() {{{
 
     /**
-     * A wrapper for programming errors triggering.
+     * A wrapper for programming Exception throwing.
      *
      * @param string $msgId  Identifier of the message
-     * @param int    $level  The php error level
      * @param array  $params An array of search=>replaces entries
      *
      * @return void
-     * @todo remove Console::triggerError() and use exceptions only
      */
-    public static function triggerError($msgId, $level, $params=array())
+    public static function throwException($msgId, $params=array())
     {
+        $msg = 'unknown error';
         if (isset(self::$errors[$msgId])) {
             $msg = str_replace(array_keys($params),
                 array_values($params), self::$errors[$msgId]);
-            trigger_error($msg, $level);
-        } else {
-            trigger_error('unknown error', $level);
         }
+        throw new \Exception($msg);
     }
 
     // }}}
diff --git a/Console/CommandLine/Argument.php b/Console/CommandLine/Argument.php
index 31485b9..1197dd2 100644
--- a/Console/CommandLine/Argument.php
+++ b/Console/CommandLine/Argument.php
@@ -83,16 +83,14 @@ class Console_CommandLine_Argument extends Console_CommandLine_Element
         // check if the argument name is valid
         if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/',
             $this->name)) {
-            Console_CommandLine::triggerError(
+            Console_CommandLine::throwException(
                 'argument_bad_name',
-                E_USER_ERROR,
                 array('{$name}' => $this->name)
             );
         }
         if (!$this->optional && $this->default !== null) {
-            Console_CommandLine::triggerError(
-                'argument_no_default',
-                E_USER_ERROR
+            Console_CommandLine::throwException(
+                'argument_no_default'
             );
         }
         parent::validate();
diff --git a/Console/CommandLine/Option.php b/Console/CommandLine/Option.php
index 539e261..9576b1b 100644
--- a/Console/CommandLine/Option.php
+++ b/Console/CommandLine/Option.php
@@ -275,21 +275,21 @@ class Console_CommandLine_Option extends Console_CommandLine_Element
         // check if the option name is valid
         if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/',
             $this->name)) {
-            Console_CommandLine::triggerError('option_bad_name',
-                E_USER_ERROR, array('{$name}' => $this->name));
+            Console_CommandLine::throwException('option_bad_name',
+                array('{$name}' => $this->name));
         }
         // call the parent validate method
         parent::validate();
         // a short_name or a long_name must be provided
         if ($this->short_name == null && $this->long_name == null) {
-            Console_CommandLine::triggerError('option_long_and_short_name_missing',
-                E_USER_ERROR, array('{$name}' => $this->name));
+            Console_CommandLine::throwException('option_long_and_short_name_missing',
+                array('{$name}' => $this->name));
         }
         // check if the option short_name is valid
         if ($this->short_name != null && 
             !(preg_match('/^\-[a-zA-Z]{1}$/', $this->short_name))) {
-            Console_CommandLine::triggerError('option_bad_short_name',
-                E_USER_ERROR, array(
+            Console_CommandLine::throwException('option_bad_short_name',
+                array(
                     '{$name}' => $this->name, 
                     '{$short_name}' => $this->short_name
                 ));
@@ -297,28 +297,28 @@ class Console_CommandLine_Option extends Console_CommandLine_Element
         // check if the option long_name is valid
         if ($this->long_name != null && 
             !preg_match('/^\-\-[a-zA-Z]+[a-zA-Z0-9_\-]*$/', $this->long_name)) {
-            Console_CommandLine::triggerError('option_bad_long_name',
-                E_USER_ERROR, array(
+            Console_CommandLine::throwException('option_bad_long_name',
+                array(
                     '{$name}' => $this->name, 
                     '{$long_name}' => $this->long_name
                 ));
         }
         // check if we have a valid action
         if (!is_string($this->action)) {
-            Console_CommandLine::triggerError('option_bad_action',
-                E_USER_ERROR, array('{$name}' => $this->name));
+            Console_CommandLine::throwException('option_bad_action',
+                array('{$name}' => $this->name));
         }
         if (!isset(Console_CommandLine::$actions[$this->action])) {
-            Console_CommandLine::triggerError('option_unregistered_action',
-                E_USER_ERROR, array(
+            Console_CommandLine::throwException('option_unregistered_action',
+                array(
                     '{$action}' => $this->action,
                     '{$name}' => $this->name
                 ));
         }
         // if the action is a callback, check that we have a valid callback
         if ($this->action == 'Callback' && !is_callable($this->callback)) {
-            Console_CommandLine::triggerError('option_invalid_callback',
-                E_USER_ERROR, array('{$name}' => $this->name));
+            Console_CommandLine::throwException('option_invalid_callback',
+                array('{$name}' => $this->name));
         }
     }
 
diff --git a/Console/CommandLine/XmlParser.php b/Console/CommandLine/XmlParser.php
index 167a543..4a0893c 100644
--- a/Console/CommandLine/XmlParser.php
+++ b/Console/CommandLine/XmlParser.php
@@ -54,8 +54,8 @@ class Console_CommandLine_XmlParser
     public static function parse($xmlfile)
     {
         if (!is_readable($xmlfile)) {
-            Console_CommandLine::triggerError('invalid_xml_file',
-                E_USER_ERROR, array('{$file}' => $xmlfile));
+            Console_CommandLine::throwException('invalid_xml_file',
+                array('{$file}' => $xmlfile));
         }
         $doc = new DomDocument();
         $doc->load($xmlfile);
@@ -117,9 +117,9 @@ class Console_CommandLine_XmlParser
                 return $doc->relaxNGValidate($path);
             }
         }
-        Console_CommandLine::triggerError(
+        Console_CommandLine::throwException(
             'invalid_xml_file',
-            E_USER_ERROR, array('{$file}' => $rngfile));
+            array('{$file}' => $rngfile));
     }
 
     // }}}
diff --git a/tests/console_commandline_addargument.phpt b/tests/console_commandline_addargument.phpt
index 6203d4d..42e5e1d 100644
--- a/tests/console_commandline_addargument.phpt
+++ b/tests/console_commandline_addargument.phpt
@@ -112,4 +112,4 @@ array(4) {
   }
 }
 
-Fatal error: argument name must be a valid php variable name (got: Some invalid name) in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: argument name must be a valid php variable name (got: Some invalid name) in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addargument_2.phpt b/tests/console_commandline_addargument_2.phpt
index ff693e5..06adf67 100644
--- a/tests/console_commandline_addargument_2.phpt
+++ b/tests/console_commandline_addargument_2.phpt
@@ -25,4 +25,4 @@ $parser->addArgument('arg3', array('default' => 'baz'));
 ?>
 --EXPECTF--
 foo bar
-Fatal error: only optional arguments can have a default value in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: only optional arguments can have a default value in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addoption_errors_1.phpt b/tests/console_commandline_addoption_errors_1.phpt
index c20f632..c22d4cc 100644
--- a/tests/console_commandline_addoption_errors_1.phpt
+++ b/tests/console_commandline_addoption_errors_1.phpt
@@ -11,4 +11,4 @@ $parser->addOption('Some invalid name');
 ?>
 --EXPECTF--
 
-Fatal error: option name must be a valid php variable name (got: Some invalid name) in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: option name must be a valid php variable name (got: Some invalid name) in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addoption_errors_2.phpt b/tests/console_commandline_addoption_errors_2.phpt
index 746dfd3..5a15560 100644
--- a/tests/console_commandline_addoption_errors_2.phpt
+++ b/tests/console_commandline_addoption_errors_2.phpt
@@ -11,4 +11,4 @@ $parser->addOption('name', array());
 ?>
 --EXPECTF--
 
-Fatal error: you must provide at least an option short name or long name for option "name" in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: you must provide at least an option short name or long name for option "name" in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addoption_errors_3.phpt b/tests/console_commandline_addoption_errors_3.phpt
index 7789ab0..35b389c 100644
--- a/tests/console_commandline_addoption_errors_3.phpt
+++ b/tests/console_commandline_addoption_errors_3.phpt
@@ -11,4 +11,4 @@ $parser->addOption('name', array('short_name'=>'d'));
 ?>
 --EXPECTF--
 
-Fatal error: option "name" short name must be a dash followed by a letter (got: "d") in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: option "name" short name must be a dash followed by a letter (got: "d") in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addoption_errors_4.phpt b/tests/console_commandline_addoption_errors_4.phpt
index 83ffebf..74dc82e 100644
--- a/tests/console_commandline_addoption_errors_4.phpt
+++ b/tests/console_commandline_addoption_errors_4.phpt
@@ -11,4 +11,4 @@ $parser->addOption('name', array('long_name'=>'d'));
 ?>
 --EXPECTF--
 
-Fatal error: option "name" long name must be 2 dashes followed by a word (got: "d") in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: option "name" long name must be 2 dashes followed by a word (got: "d") in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addoption_errors_5.phpt b/tests/console_commandline_addoption_errors_5.phpt
index 1b7eb5e..67c1cd4 100644
--- a/tests/console_commandline_addoption_errors_5.phpt
+++ b/tests/console_commandline_addoption_errors_5.phpt
@@ -11,4 +11,4 @@ $parser->addOption('name', array('short_name'=>'-d', 'action'=>true));
 ?>
 --EXPECTF--
 
-Fatal error: invalid action for option "name". in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: invalid action for option "name". in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addoption_errors_6.phpt b/tests/console_commandline_addoption_errors_6.phpt
index 5507c2c..15c488d 100644
--- a/tests/console_commandline_addoption_errors_6.phpt
+++ b/tests/console_commandline_addoption_errors_6.phpt
@@ -11,4 +11,4 @@ $parser->addOption('name', array('short_name'=>'-d', 'action'=>'Inexistant'));
 ?>
 --EXPECTF--
 
-Fatal error: unregistered action "Inexistant" for option "name". in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: unregistered action "Inexistant" for option "name". in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_addoption_errors_7.phpt b/tests/console_commandline_addoption_errors_7.phpt
index 5a00572..0e5e5ba 100644
--- a/tests/console_commandline_addoption_errors_7.phpt
+++ b/tests/console_commandline_addoption_errors_7.phpt
@@ -11,4 +11,4 @@ $parser->addOption('name', array('short_name'=>'-d', 'action'=>'Callback'));
 ?>
 --EXPECTF--
 
-Fatal error: you must provide a valid callback for option "name" in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: you must provide a valid callback for option "name" in %sCommandLine.php on line %d
diff --git a/tests/console_commandline_fromxmlfile_error.phpt b/tests/console_commandline_fromxmlfile_error.phpt
index 5d03550..a3d5c20 100644
--- a/tests/console_commandline_fromxmlfile_error.phpt
+++ b/tests/console_commandline_fromxmlfile_error.phpt
@@ -16,4 +16,4 @@ $parser->parse();
 ?>
 --EXPECTF--
 
-Fatal error: XML definition file "%sunexisting.xml" does not exists or is not readable in %sCommandLine.php on line %d
+Fatal error: Uncaught Exception: XML definition file "%sunexisting.xml" does not exists or is not readable in %sCommandLine.php on line %d
