反对在 if 子句中返回布尔值
我对各种变量何时以及如何返回还不够了解。考虑到我有一个条件语句,其中有一个对象要在其中进行验证。我说得对吗,这是作为布尔值返回的。
if($id = $oE->validate($_POST, $_FILES)){
...
}
我真正想要的是如果有任何错误,它会返回一个错误数组,否则它将返回更新内容的 $id 。
有了上面的内容,如果 validate() 对象返回任何值,它似乎会返回布尔 true ?
I don't know enough about when and how various variables are returned. Considering I have an conditional statement with an object to validate inside of this. Am I right that this is returned as a boolean value.
if($id = $oE->validate($_POST, $_FILES)){
...
}
What I really want is for this to return an array of errors if there are any errors, otherwise it will return the $id of the updated content.
With this above, it seems to return a boolean true if any value at all is returned by the validate() object??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PHP 将任何非零值解释为 true。您需要的是传递一个包含任何错误代码的引用,并让函数在失败时返回 false 或在成功时返回 id。 IE:
PHP interprets any non-zero value as true. What you need is to pass a reference which holds any error codes, and get the function to either return false on failure or the id on success. ie: