2

I should be getting an offset warning error in this code but it shows nothing. What am i missing ?

I have turned on error reporting etc.

<?php
$info = null;
$value = 'string';
if ($value == $info['firstname']){
 echo 'true';
}else{
 echo 'false';
}
?>
4
  • 1
    Interesting. This only gives an error in PHP7.4.0beta1 onward... 3v4l.org/ZvNBA Commented Sep 26, 2019 at 11:43
  • I know this is not the answer to your problem, but surely just checking if the element exists is a common enough check that this problem (IMHO) should never matter in real code. Commented Sep 26, 2019 at 11:50
  • 1
    @NigelRen I agree. This is not a problem but sometime we just dont bother checking if every element exist or not depending on the situation. This errors then help so much actually. Commented Sep 26, 2019 at 12:01
  • 1
    In answer to your now-deleted question, yes, you can make a website in PHP without using classes (object orientation, or OO). OO can be helpful in simplifying complex systems, but you don't have to use it. Commented Oct 13, 2019 at 10:03

1 Answer 1

3

Prior to version 7.4 Undefined index throws for arrays only:

<?php
$info = [];
$value = 'string';
if ($value == $info['firstname']) {
 echo 'true';
} else {
 echo 'false';
}
?>
Sign up to request clarification or add additional context in comments.

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.