0

I am currently developing in a machine that is running Ubuntu 16.04 LTS with Apache 2.4.18. I use Google Chrome Version 58.0.3029.81 (64-bit) as browser.

When I type phpinfo(); in my PHP scripts running on localhost, I get this:

PHP Version 7.0.18-1+deb.sury.org~xenial+1
display_errors On
error_reporting 32767

Both in "local value" and "master value".

The problem is that I cannot see any errors when debugging inside my PHP classes, no matter what I try. I've tried to ini_set both display_errors and error_reporting in the index.php of my application, but it just does not work anyway, I just keep getting blank pages that have no output that I can examine when viewing the source code.

I have tried to access the apache2 log folder and use tail -f myproject.error.log, but I only get old errors that have no relevant information for me.

I also tried to try logging the PHP errors with error_logging, but I guess that I do not have set the right permissions for the folder / log itself, because the folder exists but there is no file within the specificied folder.

I am legit going crazy with this problem, because it makes debugging my code a complete nightmare, since I am a beginner in PHP development and it is so frustrating to not be able to see my errors as I try to develop the code.

I created my PHP application following this tutorial https://github.com/PatrickLouys/no-framework-tutorial/. I am using the "Woops" library for error handling.

Any help is appreciated, thanks in advance.

Oriol A.
  • 1
  • 4
  • Are errors showing outside of your classes? – Ryan Tuosto May 03 '17 at 15:44
  • Yes they do appear. – Oriol A. May 03 '17 at 15:50
  • http://stackoverflow.com/questions/10687492/php-classes-and-error-messaging – Ryan Tuosto May 03 '17 at 15:52
  • Added `error_reporting("E_ALL")` (strict_types enabled) on the top of my Controller and Model but the problem remains the same :( – Oriol A. May 03 '17 at 15:54
  • No, don't put E_ALL in quotes! That effectively casts it to integer 0 and probably disabled error reporting. Use `error_reporting(E_ALL);` with a constant, not string. – Michael Berkowski May 03 '17 at 16:29
  • Greetings, and thanks for letting me know this. I am a complete newbie, and I was having issues with `declare(strict_types) = 1` from PHP 7.0+. The problem still persists, however. I just keep getting blank pages without any source code that I can debug or refer to. – Oriol A. May 04 '17 at 09:28

1 Answers1

0

After testing so many different things, I came up with a solution myself.

My Apache server was configurated properly. All I had to do was add the following lines to the top of my "Boostrap.php" file, the file that is included in my index.php file.

So, the Bootstrap.php file begins like this:

<?php declare(strict_types = 1);

namespace Myproject;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/Includes/config.php';
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', "On");
ini_set('log_errors', "On");

Basically if you are using strict_types = 1 you have to declare the ini_set instructions as Strings, and the Bootstrap file (or your autoloader file) has to contain the Error Reporting / Displaying instructions, not your index.php.

Oriol A.
  • 1
  • 4