开发者

isset needs to be used on all variables in if statements?

开发者 https://www.devze.com 2023-03-21 03:11 出处:网络
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(

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 no开发者_Python百科t, 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消