0

If I use an if statement like,

<?php if(strlen($variable) >=3) { ... } ?>

and the variable isn't actually set, this would bring me an error in PHP 5(3.6). But if I use isset() and strlen(), it would not. However, in PHP 4(4.9), when I use only strlen(), it comes through completely fine, without any errors.

Is this something that has changed since version 4.4.9? If not, is there a way I can bring back the old fashioned way of checking variables in php.ini? I find it really strange that you'd have to run both of these functions on a variable, as it really makes the code more messy than necessary. Especially if you're working with ternary operators...

To be exact, I'm working on a GET variable, and I'm getting these kind of errors:
Undefined index: x in file.php on line x

Nisto
  • 751
  • 1
  • 5
  • 4
  • 2
    Please read my answer to [isset() and empty() make code ugly](http://stackoverflow.com/questions/1960509/isset-and-empty-make-code-ugly). You *want* warnings for non-existent variables. – deceze Jul 15 '11 at 22:32
  • And no, you don't need to use `isset` on *all* variables always, only on those **that may not be set**. – deceze Jul 15 '11 at 22:36
  • Oh, I'm sorry for the duplicate. This explains it all, thanks. – Nisto Jul 15 '11 at 22:51

1 Answers1

2

Although I agree with @deceze's comment, the reason you are seeing these messages, is not a difference between php 4 and php 5 but a difference in your error reporting settings. Now you are showing E_NOTICE and before you were not.

jeroen
  • 91,079
  • 21
  • 114
  • 132