2

I am creating my own framework as a learning process. There is a config file, where people can set whether the framework is in development mode or not.

<?PHP
$project[security][dev_mode] = true;
?>

Display_startup_errors is defined in .htaccess, to indicate if syntax errors should be shown. I would prefer if users don't need to mess with the .htaccess file, so that it 'adjusts' to the settings in the config file. Anyone got an idea if and how it is possible to somehow let .htaccess check the contents of the php file and act accordingly?

A solution which sets the display_startup_errors in an other way than .htaccess is welcome too ;-).

Many thanks in advance!

5
  • 1
    display_startup_errors is going to be something people will want to set themselves. I wouldn't want a php framework to try and take control of the http server. Having said that, I don't know that theres an easy way to accomplish what you're talking about. htaccess is just a file of directives iirc. Commented Mar 27, 2013 at 0:52
  • You're probably right, but this framework won't be distributed on a large scale ;-). Thanks. Commented Mar 27, 2013 at 0:54
  • Why use .htaccess to display error instead of ini_se() configuration of php? Commented Mar 27, 2013 at 0:55
  • @kaii What I understood is that syntax errors cannot be set using ini_set()... Otherwise, is there somehow a possibility to overrule the display_startup_errors setting set using .htaccess in the php script? Commented Mar 27, 2013 at 0:58
  • @dirk It is possible to diplay syntax error using php.. :) Commented Mar 27, 2013 at 1:03

2 Answers 2

1

Try

<?php
$iDevMode = ( $project['security']['dev_mode'] ) ? 1 : 0;

ini_set('display_errors', $iDevMode);
?>

To toggle based on the definition. This is an ugly ternary operation (that you could convert to an if statement for practice) and will need to be processed very early in your program.

Also note that PHP will throw a notice for not encapsulating your associative array references in quotes, as I have above.

Sign up to request clarification or add additional context in comments.

1 Comment

As the script terminates as soon as it notices the syntax error (before processing any code), I understood that display_startup_errors cannot be set using ini_set...
1

An alternatives for the use of .htaccess in handling error is creating a configurable php file that can be set upon the stages of development,production and testing just like other frameworks does.

 * You can load different configurations depending on your
 * current environment. Setting the environment also influences
 * things like logging and error reporting.
 *
 * This can be set to anything, but default usage is:
 *
 *     development
 *     testing
 *     production
 *
 * NOTE: If you change these, also change the error_reporting() code below
 *
 */
    define('ENVIRONMENT', 'development');
/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

Or manually try to use ini_set() to properly set the configuration for error handling to on

// change settings for error handler to show errors
// $this setup is used for checking errors for development to be shown.... 
ini_set('display_errors', 1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.