PHP Error reporting

PHP error reporting displays error messages if there are any errors present in the code while running it like parse errors, runtime error etc.. The error reporting can be configured in php.ini file which is the PHP initialization file. In the php.ini file if we navigate to the error reporting section we could see that there are different type of the error level constants present which can be used to display different kinds of errors. This error level constants can be controlled by the bitwise operators

  • | bitwise OR

  • ^ bitwise XOR

  • & bitwise AND

  • ~ bitwise NOT

  • ! boolean NOT

By default, PHP is set to take action on all errors, notices and warnings EXCEPT those related to E_NOTICE and E_STRICT, which together cover best practices and recommended coding standards in PHP. For performance reasons, this is the recommend error reporting setting. Your production server shouldn’t be wasting resources complaining about best practices and coding standards. That’s what development servers and development settings are for.

Error Level Constants:

  • E_ALL – All errors and warnings (includes E_STRICT as of PHP 5.4.0)

  • E_ERROR – fatal run-time errors

  • E_RECOVERABLE_ERROR – almost fatal run-time errors

  • E_WARNING – run-time warnings (non-fatal errors)

  • E_PARSE – compile-time parse errors

  • E_NOTICE – run-time notices (these are warnings which often result a bug in your code, but it’s possible that it was intentional (e.g., using an uninitialized variable and relying on the fact it is automatically initialized to an empty string)

  • E_STRICT – run-time notices, enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code

  • E_CORE_ERROR – fatal errors that occur during PHP’s initial startup

  • E_CORE_WARNING – warnings (non-fatal errors) that occur during PHP’s initial startup

  • E_COMPILE_ERROR – fatal compile-time errors

  • E_COMPILE_WARNING – compile-time warnings (non-fatal errors)

  • E_USER_ERROR – user-generated error message

  • E_USER_WARNING – user-generated warning message

  • E_USER_NOTICE – user-generated notice message

  • E_DEPRECATED – warn about code that will not work in future versions of PHP

  • E_USER_DEPRECATED – user-generated deprecation warnings

The usage of the error level constants can be found in the php.ini file. In the php.ini file go to the error handling and logging section to see the common usage techniques of these error level constants.

All these error constants are assigned to a variable called error_reporting.

error_reporting_variable

If you come up with any doubts while reading through the php.ini file please feel free to comment. Also like always I welcome all the suggestions. Thank you.

Advertisements

Learning PHP – Starting my journey of becoming a full stack web developer.

Introduction

In this series, we would be trying to learn some basics of PHP and also some advanced stuff. By the end of this series we would try to implement a to-do list application which will support single user. Being a newbie to PHP programming, I will also be learning along this series of blog posts. So what is PHP? PHP is a server side scripting language. PHP means PHP hypertext pre-processor which is a recursive acronym that means an acronym containing another acronym inside it. The PHP inside it stands for personal homepage as initially it was called. PHP was originally created by Rasmus lerdorf in 1994.

Installing PHP

 

I won’t be covering any other installation methods because it may found easily on Google. But instead I will covering how I installed PHP in my computer for learning purpose. To run PHP locally we need a web server. For this I installed WAMP web server. Installation of WAMP webserver is pretty much standard as you can download the executable from their website and install it simply by pressing next at each dialogue box until the installation is finished. After the WAMP webserver is installed you need to start the server in order to access the WWW directory of the webserver. WWW directory is where the source files of the PHP application or HTML or css files are kept. So whenever you want to test a PHP file, copy the PHP file to the WWW directory and open it in the web browser. WAMP server is an application stack that contains several applications to run PHP files.  WAMP server stands for windows, apache, mysql, PHP server.

So that’s it for the first post on this series. But I know lot of you may have doubts regarding the installation process feel free to ask me through the comment section. Also I appreciate your suggestions and feedback’s too.