意见?当给定undef var时,foreach()抛出警告是_GOOD_吗? [英] Opinions? Is it _GOOD_ that foreach() throws warning when given undef var?

查看:74
本文介绍了意见?当给定undef var时,foreach()抛出警告是_GOOD_吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我只是想知道PHP上发表此警告的流行观点:


警告:提供的参数无效foreach()in
/home/boogerpic/public_html/my.php on line 6


当出现一个未定义的变量时。


我有必要警告一个不可接受的定义的var是否通过但是

似乎_GOOD_对我来说不需要


- 让我的函数返回空数组

- 将数组声明为将从函数接收数组的变量

- 在每个foreach周围放置条件


只是为了避免警告。


意见?


jg

Hi all,

I was just wondering what popular opinion is on PHP giving this warning:

Warning: Invalid argument supplied for foreach() in
/home/boogerpic/public_html/my.php on line 6

when presented with an indefined variable.

It makes sense to me to warn if an unacceptably defined var is passed but it
does not seem _GOOD_ to me to have to

- have my functions return empty arrays
- declare as arrays the vars which will receive arrays from functions
- place conditionals around every foreach

just to avoid the warning.

Opinions?

jg

推荐答案

" jerrygarciuh"写道:
"jerrygarciuh" wrote:
大家好,

我只是想知道什么流行的意见是关于PHP给予
这个警告:

警告:无效在第6行的/home/boogerpic/public_html/my.php中为foreach()提供的参数

当出现一个未定义的变量时。

这很有意义告诉我是否通过了一个不可接受的定义的var但它似乎不是_GOOD_给我的

- 让我的函数返回空数组
- 声明为数组的vars将接收来自
函数的数组
- 在每个foreach周围放置条件

只是为了避免警告。

意见?

jg
Hi all,

I was just wondering what popular opinion is on PHP giving
this warning:

Warning: Invalid argument supplied for foreach() in
/home/boogerpic/public_html/my.php on line 6

when presented with an indefined variable.

It makes sense to me to warn if an unacceptably defined var is
passed but it
does not seem _GOOD_ to me to have to

- have my functions return empty arrays
- declare as arrays the vars which will receive arrays from
functions
- place conditionals around every foreach

just to avoid the warning.

Opinions?

jg




在php中,您会收到有关使用任何未定义变量的警告。我个人认为这是件好事。
。通过在

中添加更多代码,为了不发出警告,你可以让自己稍后获得一些麻烦的错误。所以现在付钱(稍微)或稍后付款(

更多)。


我相信对此有不同的意见,但我是为了一个

盎司的预防......


-
http://www.dbForumz.com/ 本文由作者的请求发布

文章单独检查是否符合使用网络标准

主题网址: http://www.dbForumz.com/PHP-Opinions...ict151233.html

访问主题网址以联系作者(reg。 req''d)。举报滥用行为: http://www.dbForumz.com/eform.php ?p = 506408



In php you get warnings for usage of any undefined variable. I
personally find it to be a good thing. By putting a bit more code in
order not to get the warning, you make it possible for yourself to
catch some pesky bugs later. So pay now (a little) or pay later (a
lot more).

I am sure there are different opinions on this, but I am for "one
ounce of prevention"...

--
http://www.dbForumz.com/ This article was posted by author''s request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Opinions...ict151233.html
Visit Topic URL to contact author (reg. req''d). Report abuse: http://www.dbForumz.com/eform.php?p=506408


使用变量进行输入是非常糟糕的编程,但尚未声明
,所以在尝试

引用这样的变量之前使用isset()是个好主意。


-

Tony Marston

http://www.tonymarston.net


" jerrygarciuh" <德***** @ no.spam.nolaflash.com>在消息中写道

news:Lgh3d.27014
It is very BAD programming to use a variable for input which has yet to be
declared, so it is a GOOD idea to use isset() before you attempt to
reference such a variable.

--
Tony Marston

http://www.tonymarston.net

"jerrygarciuh" <de*****@no.spam.nolaflash.com> wrote in message
news:Lgh3d.27014


ni.11050@okepread01 ...
ni.11050@okepread01...
大家好,

我只是想知道关于PHP的流行观点是什么给出了这个警告:

警告:在/home/boogerpic/public_html/my.php中为foreach()提供的参数无效第6行

当出现一个未定义的变量时。

我有必要警告一个不可接受的定义的var是否通过但是

对我来说似乎没有_GOOD_

- 让我的函数返回空数组
- 将数组声明为将从函数接收数组的变量
- 在每个foreach周围放置条件

只是为了避免警告。

意见?

Hi all,

I was just wondering what popular opinion is on PHP giving this warning:

Warning: Invalid argument supplied for foreach() in
/home/boogerpic/public_html/my.php on line 6

when presented with an indefined variable.

It makes sense to me to warn if an unacceptably defined var is passed but
it
does not seem _GOOD_ to me to have to

- have my functions return empty arrays
- declare as arrays the vars which will receive arrays from functions
- place conditionals around every foreach

just to avoid the warning.

Opinions?

jg



这篇关于意见?当给定undef var时,foreach()抛出警告是_GOOD_吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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