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 7007483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:36:47+00:00 2026-05-27T21:36:47+00:00

This question specifically relates to my experience with PHP, but there’s no reason why

  • 0

This question specifically relates to my experience with PHP, but there’s no reason why it shouldn’t apply to other languages.

Having set ERROR_REPORTING(E_ALL); during testing, I noticed that I had some notices, such as Notice: Undefined offset: 0 in ChrisW/public_html/admin.php on line 122. This comes about as I store warnings about a form (unfilled values, invalid values, etc) in an array, and then access them:

echo $errorsArray[0] . '<label for="name" id="name-label">Your Name</label>
<input id="name" name="name" value="' . $name . '" />';

with my errors array being $errorsArray = array($nameError, $emailError); in my validation function. The 1st time the page is loaded, I show the form:

if(count($_POST) == 0)
{
  $name="";
  $email="";
  $errorsArray = array();
  form_display($name, $number, $errorsArray); 
}

In an ideal world:

  • does it matter about the notices?
  • should I initialise the array by doing $errorsArray("","");, or
  • Should I check if the array is empty when I reference it (such as by changing echo $errorsArray[0] to echo (count($errorsArray[0])==0 ? "" : $errorsArray[0])?

Hopefully, there’ll be a fairly black and white answer – I don’t want to cause a long discussion!

  • 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-27T21:36:48+00:00Added an answer on May 27, 2026 at 9:36 pm

    Production code SHOULD NOT raise notices. This causes scroll blindness – you get used to having a lot of meaningless messages, so you don’t notice the important one (until it’s too late).

    Random comments:

    • it’s not really important how you avoid notices, in your case it might be initializing $errorsArray to an empty array;
    • holding errors in an array like that is probably not the best idea anyway. Now you have two styles of passing data to your view: one by global variables ($name, $password), one by values indexed by numbers ($errorsArray[0], $errorsArray[1]). The first one is better, the second one is OK, and you could think of some better ones ($data[‘name’][‘errors’]). But the general rule is: stick to one way of doing things. As an old Polish saying goes: “może być chujowo, byle jednakowo” (roughly translated: might not be the best way, but at least it’s uniform).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question relates specifically to JavaScript, but I imagine would apply to any language.
This question would probably apply equally as well to other languages with C-like multi-line
This question relates to Java collections - specifically Hashtable and Vector - but may
(This question specifically in C#, but applies generally to .NET) I have a largish
Unlike the other posts about the task delete all tables, this question is specifically
This is not technically a programming question but it does specifically relate to a
This question covers a broad range of programming languages; however, I am specifically working
This question is specifically related to overriding the equals() method for objects with a
I found a couple questions similar to this, but not specifically for .NET projects,
This is specifically related to the accepted answer of another question I asked .

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.