我看到了this thread on a forum,这让我将线程中提到的问题与整数范围联系起来。
基本上,线程是关于存储一个大整数并将输出作为负数。
但是我找不到有关libyaml和PHP YAML扩展的整数范围的任何信息。当用非常大的数字调用yaml_emit()时,它会被转换/截断吗?
例如,如果使用一个非常大的整数调用private boolean operateWebDriver(String operation, String Locator,String value, String objectName) throws Exception {
boolean testCaseStep = false;
try {
System.out.println("Operation execution in progress");
WebElement temp = getElement(Locator, objectName);
//Trying to click on email.
if(operation.equalsIgnoreCase("Click_anElement")){
if(temp.equals(value)){
temp.click();
}
}
//Trying to verify email.
if (operation.equalsIgnoreCase("Verify_Email")) {
System.out.println("Verify--->" + temp);
if(temp.equals(value)){
System.out.println("Verified");
}
else {
System.out.println("Not Verified");
}
}
testCaseStep = true;
} catch (Exception e) {
System.out.println("Exception occurred operateWebDriver"+ e.getMessage());
// Take screenshot if any test-case is not working.
System.out.println("Taking Screen Shot");
TakesScreenshot ts=(TakesScreenshot)driver;
File source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("./Screenshots/"+screenshotName+".png"));
System.out.println("Screenshot taken");
}
return testCaseStep;
}
public WebElement getElement(String locator, String objectName) throws Exception {
WebElement temp = null;
System.out.println("Locator-->" + locator);
if (locator.equalsIgnoreCase("id")) {
temp = driver.findElement(By.id(objectName));
}
else if (locator.equalsIgnoreCase("xpath")) {
temp = driver.findElement(By.xpath(objectName));
System.out.println("xpath temp ----->" + temp);
}
else if (locator.equalsIgnoreCase("xpath1")){
String row_xpath_end= "]";
for(int rowNum=1; rowNum<=10; rowNum++){
temp = driver.findElement(By.xpath(objectName+rowNum+row_xpath_end));
}
}
return temp;
}
,但该整数在当前PHP二进制文件允许的范围内,结果会不同吗?
答案 0 :(得分:0)
这些是我在当地做的测试:
$ php -v; echo "==="; php --re yaml | head -n 1; echo "==="; php -r 'var_dump(PHP_INT_SIZE); echo yaml_emit([0x7FFFFFFF + 1, -0x80000000 - 1]);'
PHP 7.0.0 (cli) (built: Dec 3 2015 09:31:42) ( ZTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
===
Extension [ <persistent> extension #32 yaml version 2.0.0RC6 ] {
===
int(8)
---
- -2147483648
- 2147483647
...
这意味着yaml_emit()
会将所有内容整数视为32位整数。如果它们超出范围,它们将被截断。
同样,即使在64位PHP二进制文件中也是如此:
yaml_emit(0xFFFFFFFF) === yaml_emit(-1)
此外,根据PECL YAML source,似乎PHP整数被处理为long
s,即使在64位系统和二进制文件上,它也会以某种方式最终成为32位有符号整数。