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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:07:48+00:00 2026-06-14T09:07:48+00:00

Sorry if it’s an irritating question (i come from a ruby background and i

  • 0

Sorry if it’s an irritating question (i come from a ruby background and i am new to PHP).

I find it kind of weird that you can’t do:

 if($defined_array['undefined_index'] == 'a string') {
     do_something();
 }

without getting slammed in the face with a warning.

  1. In this particular case, if the variable doesn’t exist, how come you get a warning ? This is a weird implementation of equality for a loosely-typed language. It would make much more sense to only get a false. Is it due to interpreter limitations ? What are the technical reasons that are behind this ? I’m just curious.
  2. Is there any function, construct, idiom or whatever that i don’t know that would avoid me to do this every 4 lines or so:

    if(isset($defined_array['undefined_index']) && $defined_array['undefined_index'] == 'a string') {
         do_something();
    }
    

    I know that i could declare every single array keys i intend to use, but what’s the point of not being forced into declaring variables before using them if PHP intends to slap you every time you do it ?

  • 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-06-14T09:07:50+00:00Added an answer on June 14, 2026 at 9:07 am

    The reason for the warning is for code safety reasons. While it’s possible that the reason the array key doesn’t exist is because it’s not supplied in this instance, it’s also possible that there was a typo in either setting or retrieving the element. Without warnings, such coding errors would be harder to notice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry if duplicated (I didn't find it) This is only to confirm that Ruby's
Sorry if this question's been asked before, but I can't seem to find an
Sorry for this simple question, but I can't solve it... There is an example:
sorry for the dummy question but I cannot find a simple and clean way
Sorry, guys.I am quite new in mysql but I do need help from getting
Sorry for the lame question, but I can't think of a decent way to
Sorry if this is stupid question, but I'm new to MATLAB. I have a
Sorry but yet another question on JavaScript. From my previous post, I was able
Sorry, if the question is too obvious. I am working from long time in

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.