Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
+----------------------------------------------------------------------+
*/

ini_set( 'display_errors' , 1 );
ini_set( 'display_startup_errors' , 1 );
error_reporting( E_ALL );

errorsAll();
ob_implicit_flush();
libxml_use_internal_errors(true);

Expand Down Expand Up @@ -121,6 +118,42 @@ function realpain( string $path , bool $touch = false , bool $mkdir = false ) :
return $path;
}

function errorsAll(): void {
$ini = [
'display_errors' => 1 + defined('STDERR'),
'display_startup_errors' => 1 + defined('STDERR'),
'error_reporting' => E_ALL,
];

foreach ($ini as $option => $value) {
$result = ini_set($option, $value);
if ($result === false) {
$errors[] = sprintf('ini setting "%s"', $option);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please throw directly. It's over engineered this way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we could do it that way, but in my well-founded opinion, it would make a big difference whether one patch or several become required on the fail-path situatio. But that might not be obvious at first glance either.

To illustrate, here’s an example from my notes:

$ php8.3 doc-base/configure.php -V
PHP Fatal error:  Uncaught Error: php.ini errors (3)
  ini setting “display_errorsx”
  ini setting “display_startup_errorsx”
  ini setting “error_reportingx” in /home/builder/local/phpdoc/doc-base/configure.php:154
Stack trace:
#0 /home/builder/local/phpdoc/doc-base/configure.php(136): errorsWrap()
#1 /home/builder/local/phpdoc/doc-base/configure.php(22): errorsAll()
#2 {main}
  triggered in /home/builder/local/phpdoc/doc-base/configure.php on line 154

# terminated with exit code 255

A typical worst-case example for demonstration purposes: The implementation of the fail-fast test has been intentionally engineered over its total scope.

}
}

if (isset($errors)) {
throw errorsWrap(sprintf('php.ini errors (%d)', count($errors)), ...$errors);
}

error_reporting(E_ALL);
}

function errorsWrap(string|null ...$err): Error|null {
$errors = null;
foreach ($err as $e) {
if (isset($e)) {
$errors[] = $e;
}
}

if (empty($errors)) {
return null;
}

return new Error(implode("\n ", $errors));
}

function errbox($msg) {
$len = strlen($msg)+4;
$line = "+" . str_repeat("-", $len) . "+";
Expand Down
Loading