我有一个必须检查基本身份验证设置凭据的功能,如果用户存在于文件.htgroup中并从文件.htpasswd检查其密码,如果匹配则不返回0,如果匹配则返回0.
if(!($authUserLine = array_shift(preg_grep("/$user:.*$/", $AuthUserFile)))) {
我在Strict Standards: Only variables should be passed by reference in /var/www/auth.php on line 54
@Test(dataProvider = "StudentDetails")
public void createStudents(String studname, String email, String phone,
String admissionno, String rollno, String standard, String section) {
try
{
driver.findElement(By.linkText("Students")).click();
driver.findElement(By.name("commit")).click();
driver.findElement(By.id("student_student_name")).sendKeys(studname);
driver.findElement(By.id("student_email")).sendKeys(email);
driver.findElement(By.id("student_phone")).sendKeys(phone);
driver.findElement(By.id("student_admission_no")).sendKeys(admissionno);
driver.findElement(By.id("student_roll_no")).sendKeys(rollno);
Select stand = new Select(driver.findElement(By.id("standard_standard_id")));
stand.selectByVisibleText(standard);
Select sec = new Select(driver.findElement(By.id("section_section_id")));
sec.selectByVisibleText(section);
driver.findElement(By.name("commit")).click();
}catch(StaleElementReferenceException e){
e.printStackTrace();
}
}
有什么问题?
答案 0 :(得分:1)
array_shift 需要将第一个参数作为引用传递,因为它需要更新您传递的数组并删除第一个元素。
为了使其有效,您需要将 preg_grep 的结果存储在变量中:
$matches = preg_grep("/$user:.*$/", $AuthUserFile);
if(!($authUserLine = array_shift($matches))) {
...
}
答案 1 :(得分:1)
从PHP.net文档开始,可以通过引用传递内容:
- 变量,即foo($ a)
- 新陈述,即foo(new foobar())
- 从函数
返回的引用 醇>
不应该通过引用传递其他表达式,因为结果是 未定义。例如,以下通过引用传递的示例 无效。
array_shift
是唯一的参数是通过引用传递的数组。 $AuthGroupFile
的返回值没有任何引用。因此错误。您应该首先将preg_grep("/$user:.*$/", $AuthUserFile);
生成的值存储到$pregGrap
变量。之后使用array_sift()
进行引用。
最终代码如下:
if(!($authUserLine = array_shift(preg_grep("/$user:.*$/", $AuthUserFile)))) {}
如果您没有传递变量,则没有任何内容可供参考指向。
谢谢!