1

我提出这个问题是因为我无法相信这个流行的验证器会以这种方式被破坏。但是我无法理解以下程序显示的行为如何被视为预期行为。这是采埃孚 1.12。我不知道有什么方法可以报告针对 ZF1 的错误,并且随着 Zend_Locale 在 ZF2 中被删除,我怀疑 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,这也指的是这篇文章。

4

1 回答 1

0

还有另一个问题(Zend_Validate_Float locale not working with hi_IN locale)已被问及与您的问题有关。
我做出了回应,我想你可能也会感兴趣。
:)
总之,我建议是'0在数字前添加'(替换'1''01')或修改Zend/Local/Format.php文件(详细信息在我的答案中)。

于 2014-04-26T12:53:57.147 回答