30 lines
1.0 KiB
PHP
30 lines
1.0 KiB
PHP
<?php
|
|
// PHP 8 Polyfill for BCG - makes count()/sizeof() safe with null
|
|
// Add to init.conf.php BEFORE anything else
|
|
|
|
set_error_handler(function($errno, $errstr, $errfile, $errline) {
|
|
// Suppress count()/sizeof() on null - PHP 8 strict
|
|
if (strpos($errstr, 'count():') !== false && strpos($errstr, 'Countable|array') !== false) {
|
|
return true; // Suppress, return 0 implicitly
|
|
}
|
|
if (strpos($errstr, 'sizeof():') !== false) {
|
|
return true;
|
|
}
|
|
// Suppress DateTime null deprecation
|
|
if (strpos($errstr, 'DateTime::__construct()') !== false) {
|
|
return true;
|
|
}
|
|
return false; // Let other errors through
|
|
}, E_ALL);
|
|
|
|
// Override count() for null safety
|
|
// Can't override built-in, but we can catch TypeErrors
|
|
set_exception_handler(function($e) {
|
|
if ($e instanceof TypeError && strpos($e->getMessage(), 'count()') !== false) {
|
|
// Log silently, return
|
|
error_log("BCG count() TypeError suppressed: " . $e->getFile() . ":" . $e->getLine());
|
|
return;
|
|
}
|
|
throw $e;
|
|
});
|