error_reporting(E_ALL) does not produce an error
When you set error_reporting(E_ALL) in a PHP script, you might expect to see every undefined variable or syntax mistake shouted out from the server. Instead, you often get a blank screen. This isn't because your error reporting configuration is broken; it's because PHP has two distinct mechanisms for handling fatal errors and uncaught exceptions, and E_ALL only covers one of them.
In your specific case, the line $thisdoesnotexist triggers a fatal error. While error_reporting(E_ALL) tells PHP to catch and report warnings, notices, and standard errors, it does not guarantee that the output will appear if the default display settings are off or if the error occurs during an operation that bypasses the standard logging path.
The most common culprit for a "blank page" is that display_errors is set to 0 (Off) in your environment. When display_errors is disabled, PHP sends the error message to the server log file rather than echoing it directly to the browser. This is often the desired behavior for production environments to prevent sensitive stack traces from leaking to users. However, if you are testing locally or debugging a script and expect immediate feedback, relying solely on ini_set('display_errors', '1') inside your script can be fragile. Configuration directives like display_errors are generally not dynamic; once the request starts, they often reflect the state of the loaded configuration rather than runtime assignments, especially depending on how the server was compiled (e.g., with zlib.output_compression interfering).
The Fatal Error Trap
The critical distinction here is between Warnings/Notices and Fatal Errors.
- A notice like accessing an undefined variable in a non-critical context might be suppressed or logged.
- A fatal error, such as using a variable that doesn't exist (
$thisdoesnotexist) in the main execution flow, usually terminates the script immediately.
If display_errors is off, the script stops executing before it can return anything to the browser. The output buffer is empty because the script died before writing any HTML. This is exactly what happens with $thisdoesnotexist. PHP attempts to evaluate that variable, hits a fatal error, and exits. Even though you set error_reporting(E_ALL), the visibility of that error depends entirely on whether display_errors allows the output stream to be flushed with the error message.
Checking Your Environment
Before assuming your code is wrong, verify where PHP is actually running. The source material mentions checking php.ini. If you are using a shared hosting environment (like cPanel) or a containerized setup (Docker), the php.ini file you edited might not be the one active for that specific process.
To confirm your settings are taking effect, try this diagnostic script:
<?php
echo 'error_reporting value: ' . error_reporting() . PHP_EOL;
echo 'display_errors value: ' . ini_get('display_errors') . PHP_EOL;
echo 'display_startup_errors value: ' . ini_get('display_startup_errors') . PHP_EOL;
?>
If this outputs 0 for display_errors, your changes to the config file have not taken effect, or the server is using a different configuration. You may need to restart the web server (Apache/Nginx) or clear opcode caches if you are running a local stack like PHP-FPM with Nginx.
Why ini_set Might Fail in Your Script
You noted that adding ini_set('display_errors', '1') didn't help. This is a known limitation. If the error occurs in a way that triggers an immediate fatal exception before the script can reach subsequent lines, or if the directive is locked by the server administrator (common on shared hosts), runtime changes won't override the compiled-in defaults.
If you are running this locally via php -S localhost:8000, ensure you haven't accidentally set display_errors=Off in your user's php.ini or .user.ini files. The order of precedence is crucial:
- User Config (
.htaccess,.user.ini, or project-specificphp.ini) - Global Config (
/etc/php/.../php.ini) - Compiled Defaults
If your global config has display_errors=Off and you don't have a user-level override, the script will remain silent.
The Solution for Debugging
To reliably see these errors during development without relying on persistent config changes, consider using an output buffer or ensuring the environment is explicitly set to show errors. However, the most robust fix is simply ensuring display_errors=On in your active configuration file and restarting the service.
Once display_errors is enabled, running that original snippet will finally reveal the fatal error message, explaining exactly why $thisdoesnotexist caused a crash. Remember that fixing the code to define the variable or check its existence is still necessary for production, but seeing the error first is half the battle.
For those using Laravel or similar frameworks, remember that framework-level error handling often suppresses these raw fatal errors by default. If you are building with LaravelCompany principles, always ensure your APP_DEBUG flag is set to true in local environments to bypass the exception rendering middleware and see the underlying PHP stack trace.
