本文介绍了意见?当给定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

推荐答案




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

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

更多)。


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

盎司的预防......


-
本文由作者的请求发布

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

主题网址:

访问主题网址以联系作者(reg。 req''d)。举报滥用行为:



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





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

10-30 01:05