通知和警告 [英] notice and warning

查看:78
本文介绍了通知和警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在php中打开了错误:


ini_set(''display_errors'',''1'');


我收到了一些通知和一些警告。


这些通知大多是缺少这样做的索引:


$ some_var = $ _REQUEST [''some_name''];


警告就是我有这样的事情:


缺少参数1 ...


函数someFoo($ var1){

if($ var1){...}

}


someFoo();


所以,我把display_errors关掉了,但是想知道我是否应该这样做/>
关于这一点的任何事情。


什么是好的编程习惯?


一般来说我更关心的是变量是否是null或empty,和

不是它是否已经设置,这就是通知。似乎是关于。
。如果我这样做:


if(isset($ var1)){


//我还是要做这个:


if($ var1){...


PHP对我来说是一种新语言,我想写正确......但是

我也不想让代码膨胀。


哦,还有一件事,我溜进了perl模式并且这样做了:

$ SOME_ARRAY {some_key}并且没有投诉,是否是kosher?


Jeff

解决方案

some_var =


_REQUEST [''some_name''];


警告是我有这样的事情:


缺少参数1 ...


函数someFoo(

var1){

if(



I turned on errors in php:

ini_set(''display_errors'',''1'');

And I got a slew of notices and a couple of warnings.

The notices are mostly missing indexes from doing things like this:

$some_var = $_REQUEST[''some_name''];

And the warnings are when I have something like this:

Missing argument 1 ...

function someFoo($var1){
if($var1){...}
}

someFoo();

So, I turned display_errors back off, but wonder if I should do
anything about the this.

What is good programming practice?

Generally I care more about whether a variable is null or empty, and
not whether it has been set, which is what the "notices" seem to be
about. If I were to do this:

if(isset($var1)){

// I''d still have to do this:

if($var1){...

PHP is a new language for me, and I''d like to write "correctly"...but
I don''t want to bloat the code either.

Oh, one more thing, I slipped into perl mode and did this:
$SOME_ARRAY{some_key} and got no complaints, Is that "kosher"?

Jeff

解决方案

some_var =


_REQUEST[''some_name''];

And the warnings are when I have something like this:

Missing argument 1 ...

function someFoo(


var1){
if(


这篇关于通知和警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆