简体   繁体   English

严格标准的PHP错误

[英]Strict Standards php error

I have a small issue with my script. 我的脚本有一个小问题。

I'm getting Strict Standards: Only variables should be passed by reference in 我越来越严格的标准:只有变量应该通过引用传递给

if( $checkDNS && ($domain = end(explode('@',$email, 2))) )

From the PHP manual : PHP手册

This array is passed by reference because it is modified by the function. 此数组通过引用传递,因为它已由函数修改。 This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference. 这意味着您必须为它传递一个实变量,而不要向它传递返回数组的函数,因为只能通过引用传递实际变量。

So you must use a variable in the end function: 因此,您必须在end函数中使用一个变量:

$domain = explode('@',$email, 2);
if( $checkDNS && ($domain = end($domain)) )

From the manual: 从手册中:

mixed end ( array &$array )

end takes the array by reference and move the internal pointer. end通过引用获取数组并移动内部指针。 Your array is the function output, so its unable to correctly modify the array by reference. 您的数组是函数输出,因此它无法通过引用正确修改数组。

Like the message says, end expects a variable because its parameter is a reference. 就像消息说的那样,end期望变量,因为它的参数是引用。

But since PHP 5.4 you can dereference arrays like that: 但是从PHP 5.4开始,您可以像这样取消引用数组:

$domain = explode('@',$email, 2)[1];

Assuming that $email always contains @ . 假设$ email始终包含@ You should assure that beforehand, otherwise end(...) would give you unexpected results too. 您应该事先确保,否则end(...)也会给您带来意想不到的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM