1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
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
|