Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 822093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:44:57+00:00 2026-05-15T02:44:57+00:00

Which would you recommend? Return an error code, such as E_USER_ERROR from a function,

  • 0

Which would you recommend?

  1. Return an error code, such as E_USER_ERROR from a function, and determine proper message higher up:

    function currentScriptFilename()
    {
      if(!isset($_SERVER['SCRIPT_FILENAME']))
      {
        //This?
        return E_USER_ERROR;
      }
      else
      {
        $url = $_SERVER['SCRIPT_FILENAME'];
        $exploded = explode('/', $url);
        return end($exploded);
      }
    }
    
  2. Execute trigger_error() from the function, with a specific error message:

    function currentScriptFilename()
    {
      if(!isset($_SERVER['SCRIPT_FILENAME']))
      {
        //Or this?
        trigger_error('$_SERVER[\'SCRIPT_FILENAME\'] is not set.', E_USER_ERROR);
      }
      else
      {
        $url = $_SERVER['SCRIPT_FILENAME'];
        $exploded = explode('/', $url);
        return end($exploded);
      }
    }
    

I am not sure if I will regret having put a bunch of error messages in my functions further down the line, since I would like to use them for other projects.

Or, would you recommend something totally different?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:44:58+00:00Added an answer on May 15, 2026 at 2:44 am

    Do not mix the matters.
    Error notification and error handling are different tasks.

    You have to use both methods simultaneously.
    If you think that $_SERVER[‘SCRIPT_FILENAME’] availability is worth an error message, you can use trigger error. However PHP itself will throw a notice if you won’t check it.

    If you want to handle this error, just check this function’s return value.
    But I would not create a special function for this task.

    So,

    if (!$filename = basename($_SERVER['SCRIPT_FILENAME']) {
      //  do whatever you want to handle this error.
    }
    

    would be enough

    Exceptions could be useful to handle errors, to know if we had any errors occurred.

    A simple example:

    try {
      $filename = basename($_SERVER['SCRIPT_FILENAME']) 
      if (!$filename) throw new Exception("no filename");
    
      $data = get_some_data_from_db() or throw new Exception("no data");
    
      $template = new Template();
     //Exception could be thrown inside of Template class as well.
    }
    catch (Exception $e) {
      //if we had any errors
      show_error_page();
    }
    $template->show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which orm you would recommend for a beginner moving from ado.net?... Thus far used
Which OS would you recommend for a development machine: Windows Server 2008 R2 or
Which programming language would you recommend to learn about data structures and algorithms in?
Which set of libraries and tools would you recommend to use for development SOAP-service
I have a label which would display strings from 0 ft to say 999
I'm choosing between the following 2 designs. Which would you recommend and why? I'm
Which would be a more appropriate repository to host a small, XCode, Objective-C based
I was just wondering which would be cheaper, using a try catch block for
I need some library which would be able to keep my urls Indexed and
I have a class which would create a bean and the bean has few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.