PHP does not work on require_once

I have a PHP script that includes (or "requires") a set of other scripts. This is effective for importing all my classes. I encountered an HTTP 500 error. I sifted through and commented on the code piecemeal to determine that it did not work in require_once in one of my files.

Here is the code:

index.php:

<?php require_once("std/classes.php"); ?> 

And std / classes.php:

 <?php RequireStandards(); RequireAddons(); function RequireStandards( ) { $ClassFiles = scandir("classes/standard"); foreach( $ClassFiles as $ClassFile ) { if( $ClassFile == "." || $ClassFile == ".." ) continue; //require_once("classes/standard/" . $ClassFile ); } } function RequireAddons() { $ClassFiles = scandir("classes"); foreach( $ClassFiles as $ClassFile ) { if( $ClassFile == "." || $ClassFile == ".." || $ClassFile == "standard" ) continue; //require_once("classes/" . $ClassFile ); } } ?> 

This code will work the way it sits, but as soon as I uncomment the request, it fails. It amazes me that I have many other sites on this server that operate almost the same way.

It seems to me that I somehow turned off the PHP error report ... which I do not know how to return to; since I just upgraded to PHP 5.3. Usually I expected that β€œI won’t be able to open the file” or some of them in my browser if PHP failed.

Maybe someone can tell me why this returns an HTTP 500, or maybe just how to enable error reporting. It will be much appreciated; this does not seem to make much sense.

+6
source share
3 answers

To enable error reporting:

 <?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once("std/classes.php"); ?> 

Hope this works.

EDIT: If this really works, be sure to turn off display errors before putting anything into a live, open environment!

+11
source

You can temporarily return an error report using the error_reporting () function, for example, to show all errors, insert the following code into your file:

error_reporting(E_ALL);

Of course, to change this forever, you have to edit the php.ini file and make sure that you enable error_reporting as well as display_errors (at least if it is not a production environment). You can also try:

ini_set('display_errors', 1);

Although this may not work if you have a fatal error on the page. Again, to enable this constantly, you will have to modify the php.ini file.

It is generally recommended that you enable display_errors only on non-production systems so that users do not receive potentially confidential information through your error messages.

In any case, you should find php errors in the apache error log, on ubuntu this is here:

/var/log/apache2/error.log

Although it depends on your distribution.

+2
source

I suggest you take a look at Startup classes

0
source

Source: https://habr.com/ru/post/913163/


All Articles