我问这是一个问题,因为我无法相信这种流行的验证器可能会以这种方式被打破。但我无法理解以下程序所显示的行为如何被视为预期的行为。这是ZF 1.12。我不知道如何报告针对ZF1的错误,并且在ZF2中删除Zend_Locale,我怀疑对ZF团队有任何兴趣。我查看了Zend源代码。我看不出这会怎么样。这里有人有什么想法吗?在遇到问题的特定情况下,值应该是db的自动增量值,因此Digits验证器也可以正常工作。这是一个展示问题的程序:
<?php
// Put library on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath('./library'),
get_include_path()
)));
require 'Zend/Locale/Format.php';
require 'Zend/Validate/Int.php';
global $mutating_locales;
echo "\n*** Showing that function checkit() does what's expected with
a value that has locale-specific formatting\n";
checkit('1000', 'en_US');
checkit('1000', 'hi_IN');
echo var_export($mutating_locales, true) . "\n\n";
echo "\n*** Showing the problem with small integers in locale hi_IN\n";
for ($i = 0; $i < 101; ++$i) {
checkit((string)$i, 'hi_IN');
}
echo "\n*** Checking every supported locale for value '1'\n";
$mutating_locales = array();
foreach (Zend_Locale::getLocaleList() as $locale => $ignore) {
checkit('1', $locale);
}
echo var_export($mutating_locales, true) . "\n";
// Function to print if $value is a valid Int in locale $locale
function checkit($value, $locale) {
global $mutating_locales;
$formatted = Zend_Locale_Format::toInteger(
$value, array('locale' => $locale));
if ($formatted !== $value) {
printf("Representation changed for locale %s, old: '%s', new: '%s'\n",
$locale, $value, $formatted);
$mutating_locales[] = $locale;
}
$validator = new Zend_Validate_Int($locale);
$valid = $validator->isValid($value);
if (! $valid) {
printf("Value '%s' is not a valid Int in locale '%s'\n",
$value, $locale);
$invalid_locales[] = $locale;
if ($formatted === $value) {
printf(" And the formatted value is identical\n");
} else {
$fmtvalid = $validator->isValid($formatted);
if (fmtvalid) {
printf(" But the formatted value is valid\n");
} else {
printf(" And the formatted value is also invalid\n");
}
}
}
}
$ php validate-int-bug.php
*** Showing that function checkit() does what's expected with
a value that has locale-specific formatting
Representation changed for locale en_US, old: '1000', new: '1,000'
Representation changed for locale hi_IN, old: '1000', new: '1,000'
array (
0 => 'en_US',
1 => 'hi_IN',
)
*** Showing the problem with small integers in locale hi_IN
Value '0' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '2' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '3' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '4' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '5' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '6' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '7' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '8' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '9' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
*** Checking every supported locale for value '1'
Value '1' is not a valid Int in locale 'ar_QA'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ar_SA'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ar_SY'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ar_TN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ar_YE'
And the formatted value is identical
Value '1' is not a valid Int in locale 'as_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'as'
And the formatted value is identical
Value '1' is not a valid Int in locale 'bn_BD'
And the formatted value is identical
Value '1' is not a valid Int in locale 'bn_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'bn'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dv_MV'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dv'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dz_BT'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dz'
And the formatted value is identical
Value '1' is not a valid Int in locale 'en_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'en_PK'
And the formatted value is identical
Value '1' is not a valid Int in locale 'gu_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'gu'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hi'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hy_AM'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hy'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kn_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kn'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kok_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kok'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ml_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ml'
And the formatted value is identical
Value '1' is not a valid Int in locale 'mr_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'mr'
And the formatted value is identical
Value '1' is not a valid Int in locale 'or_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'or'
And the formatted value is identical
Value '1' is not a valid Int in locale 'pa_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'pa_PK'
And the formatted value is identical
Value '1' is not a valid Int in locale 'pa'
And the formatted value is identical
Value '1' is not a valid Int in locale 'sa_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'sa'
And the formatted value is identical
Value '1' is not a valid Int in locale 'bn'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dv_MV'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dv'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dz_BT'
And the formatted value is identical
Value '1' is not a valid Int in locale 'dz'
And the formatted value is identical
Value '1' is not a valid Int in locale 'en_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'en_PK'
And the formatted value is identical
Value '1' is not a valid Int in locale 'gu_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'gu'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hi_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hi'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hy_AM'
And the formatted value is identical
Value '1' is not a valid Int in locale 'hy'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kn_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kn'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kok_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'kok'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ml_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'ml'
And the formatted value is identical
Value '1' is not a valid Int in locale 'mr_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'mr'
And the formatted value is identical
Value '1' is not a valid Int in locale 'or_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'or'
And the formatted value is identical
Value '1' is not a valid Int in locale 'pa_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'pa_PK'
And the formatted value is identical
Value '1' is not a valid Int in locale 'pa'
And the formatted value is identical
Value '1' is not a valid Int in locale 'sa_IN'
And the formatted value is identical
Value '1' is not a valid Int in locale 'sa'
And the formatted value is identical
修改:我发现了如何发布ZF1问题,因此现在发布在https://github.com/zendframework/zf1/issues/166,这也是指此帖子。
答案 0 :(得分:0)
还有另一个问题(Zend_Validate_Float locale not working with hi_IN locale)被问及与你有关的问题
我做了回应,我认为你也可能会对此感兴趣
:)
总之,我建议在数字前添加'0
'(将'1'
替换为'01'
)或修改Zend/Local/Format.php
文件(详细信息在我的{{3}中}})。