WordPress The Right Way
English en-US
English en-US
  • WordPress The Right Way
  • Getting Started
  • Debugging
    • Error Logging
    • Handling Errors
    • Tools
    • Constants of wp-config.php
  • Data
  • Core
  • Code Style Guide
  • I18n
  • JavaScript
  • Multisite
  • Queries
    • User Queries
    • SQL
    • Taxonomy and Term Queries
    • Comment Queries
    • Post Queries
  • Routing
    • The Main Loop & Template Loading
    • What Are Query Variables and Where Do They Come From?
    • Clashes, Slugs, & Debugging
    • Rewrite Rules
  • Security
    • Secure HTTP
    • Standalone PHP Files
  • Servers And Deployment
    • Migrations
    • WP CLI
  • Templates
  • Testing
    • Testing Theory
      • Test Driven Development
      • Unit Testing
      • Behavior Driven Development
    • Testing Plugins
    • WP_UnitTestCase
  • Widgets
  • Community
  • Credits
Powered by GitBook
On this page
  • Warnings vs Errors
  • PHP Error Reporting
  • The @ operator
  1. Debugging

Error Logging

There are several kinds of error logging, but the most basic are:

  • Displaying errors on the frontend

  • Writing errors to a log file

  • Not displaying anything at all

In a production/live environment, you want to write errors to a log file.

Warnings vs Errors

Depending on how PHP is configured, warnings will also be shown. A warning is something that does not stop PHP from running but indicates a problem might have occurred. For example:

$my_array = array(
    'alice' => 5,
    'bob' => 6
);
echo $my_array['eve'];

Here, I am echoing the 'eve' entry in $my_array, but there is no such entry. PHP responds by creating an empty value and logging a warning. Warnings are indicators of bugs and mistakes.

PHP Error Reporting

Depending on what was defined in your php.ini, PHP will have an error reporting level. Everything below that level will be ignored or considered a warning. Everything above it will be considered an error. This can vary from server to server.

The @ operator

Never use the @ operator. It's used to hide errors and warnings in code, but it doesn't do what people expect it to do.

@ works by setting the error reporting level on a command so that no error is logged. It doesn't prevent the error from happening, which is what people expect it to do. This can mean fatal errors are not caught or logged. Avoid using the @ operator, and treat all instances of it with suspicion.

PreviousDebuggingNextHandling Errors

Last updated 4 years ago