Coder Social home page Coder Social logo

polyfill's Introduction

Symfony Polyfill

This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions. It is intended to be used when portability across PHP versions and extensions is desired.

Polyfills are provided for:

  • the apcu extension when the legacy apc extension is installed;
  • the ctype extension when PHP is compiled without ctype;
  • the mbstring and iconv extensions;
  • the uuid extension;
  • the MessageFormatter class and the msgfmt_format_message functions;
  • the Normalizer class and the grapheme_* functions;
  • the utf8_encode and utf8_decode functions from the xml extension or PHP-7.2 core;
  • the Collator, NumberFormatter, Locale and IntlDateFormatter classes, limited to the "en" locale;
  • the intl_error_name, intl_get_error_code, intl_get_error_message and intl_is_failure functions;
  • the idn_to_ascii and idn_to_utf8 functions;
  • a Binary utility class to be used when compatibility with mbstring.func_overload is required;
  • the spl_object_id and stream_isatty functions introduced in PHP 7.2;
  • the mb_ord, mb_chr and mb_scrub functions introduced in PHP 7.2 from the mbstring extension
  • the sapi_windows_vt100_support function (Windows only) introduced in PHP 7.2;
  • the PHP_FLOAT_* constant introduced in PHP 7.2;
  • the PHP_OS_FAMILY constant introduced in PHP 7.2;
  • the is_countable function introduced in PHP 7.3;
  • the array_key_first and array_key_last functions introduced in PHP 7.3;
  • the hrtime function introduced in PHP 7.3;
  • the JsonException class introduced in PHP 7.3;
  • the get_mangled_object_vars, mb_str_split and password_algos functions introduced in PHP 7.4;
  • the fdiv function introduced in PHP 8.0;
  • the get_debug_type function introduced in PHP 8.0;
  • the preg_last_error_msg function introduced in PHP 8.0;
  • the str_contains function introduced in PHP 8.0;
  • the str_starts_with and str_ends_with functions introduced in PHP 8.0;
  • the ValueError class introduced in PHP 8.0;
  • the UnhandledMatchError class introduced in PHP 8.0;
  • the FILTER_VALIDATE_BOOL constant introduced in PHP 8.0;
  • the get_resource_id function introduced in PHP 8.0;
  • the Attribute class introduced in PHP 8.0;
  • the Stringable interface introduced in PHP 8.0;
  • the PhpToken class introduced in PHP 8.0 when the tokenizer extension is enabled;
  • the array_is_list function introduced in PHP 8.1;
  • the enum_exists function introduced in PHP 8.1;
  • the MYSQLI_REFRESH_REPLICA constant introduced in PHP 8.1;
  • the ReturnTypeWillChange attribute introduced in PHP 8.1;
  • the CURLStringFile class introduced in PHP 8.1 (but only if PHP >= 7.4 is used);
  • the AllowDynamicProperties attribute introduced in PHP 8.2;
  • the SensitiveParameter attribute introduced in PHP 8.2;
  • the SensitiveParameterValue class introduced in PHP 8.2;
  • the Random\Engine interface introduced in PHP 8.2;
  • the Random\CryptoSafeEngine interface introduced in PHP 8.2;
  • the Random\Engine\Secure class introduced in PHP 8.2 (check arokettu/random-polyfill for more engines);
  • the odbc_connection_string_is_quoted function introduced in PHP 8.2;
  • the odbc_connection_string_should_quote function introduced in PHP 8.2;
  • the odbc_connection_string_quote function introduced in PHP 8.2;
  • the ini_parse_quantity function introduced in PHP 8.2;
  • the json_validate function introduced in PHP 8.3;
  • the Override attribute introduced in PHP 8.3;
  • the mb_str_pad function introduced in PHP 8.3;
  • the ldap_exop_sync function introduced in PHP 8.3;
  • the ldap_connect_wallet function introduced in PHP 8.3;
  • the stream_context_set_options function introduced in PHP 8.3;
  • the str_increment and str_decrement functions introduced in PHP 8.3;
  • the Date*Exception/Error classes introduced in PHP 8.3;
  • the SQLite3Exception class introduced in PHP 8.3;
  • the mb_ucfirst and mb_lcfirst functions introduced in PHP 8.4;

It is strongly recommended to upgrade your PHP version and/or install the missing extensions whenever possible. This polyfill should be used only when there is no better choice or when portability is a requirement.

Compatibility notes

To write portable code between PHP5 and PHP7, some care must be taken:

  • \*Error exceptions must be caught before \Exception;
  • after calling error_clear_last(), the result of $e = error_get_last() must be verified using isset($e['message'][0]) instead of null !== $e.

Usage

When using Composer to manage your dependencies, you should not require the symfony/polyfill package, but the standalone ones:

  • symfony/polyfill-apcu for using the apcu_* functions,
  • symfony/polyfill-ctype for using the ctype functions,
  • symfony/polyfill-php54 for using the PHP 5.4 functions,
  • symfony/polyfill-php55 for using the PHP 5.5 functions,
  • symfony/polyfill-php56 for using the PHP 5.6 functions,
  • symfony/polyfill-php70 for using the PHP 7.0 functions,
  • symfony/polyfill-php71 for using the PHP 7.1 functions,
  • symfony/polyfill-php72 for using the PHP 7.2 functions,
  • symfony/polyfill-php73 for using the PHP 7.3 functions,
  • symfony/polyfill-php74 for using the PHP 7.4 functions,
  • symfony/polyfill-php80 for using the PHP 8.0 functions,
  • symfony/polyfill-php81 for using the PHP 8.1 functions,
  • symfony/polyfill-php82 for using the PHP 8.2 functions,
  • symfony/polyfill-php83 for using the PHP 8.3 functions,
  • symfony/polyfill-php84 for using the PHP 8.4 functions,
  • symfony/polyfill-iconv for using the iconv functions,
  • symfony/polyfill-intl-grapheme for using the grapheme_* functions,
  • symfony/polyfill-intl-idn for using the idn_to_ascii and idn_to_utf8 functions,
  • symfony/polyfill-intl-icu for using the intl functions and classes,
  • symfony/polyfill-intl-messageformatter for using the intl messageformatter,
  • symfony/polyfill-intl-normalizer for using the intl normalizer,
  • symfony/polyfill-mbstring for using the mbstring functions,
  • symfony/polyfill-util for using the polyfill utility helpers.
  • symfony/polyfill-uuid for using the uuid_* functions,

Requiring symfony/polyfill directly would prevent Composer from sharing correctly polyfills in dependency graphs. As such, it would likely install more code than required.

Design

This package is designed for low overhead and high quality polyfilling.

It adds only a few lightweight require statements to the bootstrap process to support all polyfills. Implementations are then loaded on-demand when needed during code execution.

If your project requires a minimum PHP version it is advisable to add polyfills for lower PHP versions to the replace section of your composer.json. This removes any overhead from these polyfills as they are no longer part of your project. The same can be done for polyfills for extensions that you require.

If your project requires php 7.0, and needs the mb extension, the replace section would look something like this:

{
    "replace": {
        "symfony/polyfill-php54": "*",
        "symfony/polyfill-php55": "*",
        "symfony/polyfill-php56": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-mbstring": "*"
    }
}

Polyfills are unit-tested alongside their native implementation so that feature and behavior parity can be proven and enforced in the long run.

License

This library is released under the MIT license.

polyfill's People

Contributors

ayesh avatar azjezz avatar backendtea avatar carusogabriel avatar davidprevot avatar derrabus avatar fabpot avatar fisharebest avatar gharlan avatar grahamcampbell avatar guilliamxavier avatar ionbazan avatar jakzal avatar jderusse avatar kalessil avatar keradus avatar lyrixx avatar nicolas-grekas avatar ogizanagi avatar ostrolucky avatar pierredup avatar spacepossum avatar stof avatar timwolla avatar tobion avatar trowbotham avatar tysonandre avatar webmozart avatar wintersilence avatar xabbuh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

polyfill's Issues

Tests fail on PHP 7.3

Using PHP 7.3 on Debian unstable, I see the following test failures:

There were 18 failures:

1) Symfony\Polyfill\Tests\Apcu\ApcuTest::testApcu
Failed asserting that false is true.

/home/km/projects/symfony-polyfill/tests/Apcu/ApcuTest.php:27

2) Symfony\Polyfill\Tests\Apcu\ApcuTest::testArrayCompatibility
Failed asserting that false matches expected 'value1'.

/home/km/projects/symfony-polyfill/tests/Apcu/ApcuTest.php:52

3) Symfony\Polyfill\Tests\Apcu\ApcuTest::testAPCUIterator
Failed asserting that false is true.

/home/km/projects/symfony-polyfill/tests/Apcu/ApcuTest.php:71

4) Symfony\Polyfill\Tests\Intl\Idn\IdnTest::testDecodeInvalid2003 with data set #0 ('xn--zcaccffbljjkknnoorrssuuxx...g9g.de', 'xn--zcaccffbljjkknnoorrssuuxx...g9g.de')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'xn--zcaccffbljjkknnoorrssuuxxd5e0a0a3ae9c6a4a9bzdzdxdudwdxd2d2d8d0dse7d6dwe9dxeueweye4eyewe9e5ewkkewc9ftfpfplwexfwf4infvf2f6f6f7f8fpg8fmgngrgrgvgzgygxg3gyg1g3g5gykqg9g.de'
+'äöüßáàăâåãąāæćĉčċçďđéèĕêěëėęēğĝġģĥħíìĭîïĩįīıĵķĺľļłńňñņŋóòŏôőõøōœĸŕřŗśŝšşťţŧúùŭûůűũųūŵýŷÿźžżðþ.de'

/home/km/projects/symfony-polyfill/tests/Intl/Idn/IdnTest.php:83

5) Symfony\Polyfill\Tests\Intl\Idn\IdnTest::testDecodeInvalid2003 with data set #1 ('xn--zcaccffbljjkknnoorrssuuxx...vda.de', 'xn--zcaccffbljjkknnoorrssuuxx...g.þ.de')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'xn--zcaccffbljjkknnoorrssuuxxd5e0a0a3ae9c8c1b0dxdvdvdxdvd3d0d6dyd8d5d4due7dveseuewe2eweue7e3esk9dxc7frf9e7kuevfuf1ilftf5f4f4f5f6fng6f8f9fpgpgtgxgwgvg1g2gzg1g3gvkog7g.þ.de'
+'äöüßáàăâåãąāæćĉčċçďđéèĕêěëėęēğĝġģĥħíìĭîïĩįīıĵķĺľļłńňñņŋóòŏôőõøōœĸŕřŗśŝšşťţŧúùŭûůűũųūŵýŷÿźžżð.þ.de'

/home/km/projects/symfony-polyfill/tests/Intl/Idn/IdnTest.php:83

6) Symfony\Polyfill\Tests\Intl\Idn\IdnTest::testUppercase2003 with data set #0 ('рф.RU', 'xn--p1ai.RU', 'рф.RU')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'xn--p1ai.RU'
+'xn--p1ai.ru'

/home/km/projects/symfony-polyfill/tests/Intl/Idn/IdnTest.php:93

7) Symfony\Polyfill\Tests\Intl\Idn\IdnTest::testUppercase2003 with data set #1 ('GUANGDONG.广东', 'GUANGDONG.xn--xhq521b', 'GUANGDONG.广东')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'GUANGDONG.xn--xhq521b'
+'guangdong.xn--xhq521b'

/home/km/projects/symfony-polyfill/tests/Intl/Idn/IdnTest.php:93

8) Symfony\Polyfill\Tests\Intl\Idn\IdnTest::testUppercase2003 with data set #2 ('renanGonçalves.COM', 'xn--renangonalves-pgb.COM', 'renangonçalves.COM')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'xn--renangonalves-pgb.COM'
+'xn--renangonalves-pgb.com'

/home/km/projects/symfony-polyfill/tests/Intl/Idn/IdnTest.php:93

9) Symfony\Polyfill\Tests\Intl\Normalizer\NormalizerTest::testConstants
Failed asserting that Array &0 (
    'FORM_C' => 4
    'FORM_D' => 2
    'FORM_KC' => 5
    'FORM_KD' => 3
    'NFC' => 4
    'NFD' => 2
    'NFKC' => 5
    'NFKD' => 3
    'NONE' => 1
) is identical to Array &0 (
    'FORM_C' => 16
    'FORM_D' => 4
    'FORM_KC' => 32
    'FORM_KC_CF' => 48
    'FORM_KD' => 8
    'NFC' => 16
    'NFD' => 4
    'NFKC' => 32
    'NFKC_CF' => 48
    'NFKD' => 8
    'NONE' => 2
).

/home/km/projects/symfony-polyfill/tests/Intl/Normalizer/NormalizerTest.php:37

10) Symfony\Polyfill\Tests\Intl\Normalizer\NormalizerTest::testIsNormalized
Failed asserting that false is true.

/home/km/projects/symfony-polyfill/tests/Intl/Normalizer/NormalizerTest.php:51

11) Symfony\Polyfill\Tests\Intl\Normalizer\NormalizerTest::testNormalize
Failed asserting that false is identical to 'déjà훈쇼™'.

/home/km/projects/symfony-polyfill/tests/Intl/Normalizer/NormalizerTest.php:68

12) Symfony\Polyfill\Tests\Intl\Normalizer\NormalizerTest::testNormalizeConformance
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'Ḋ'
+'Ḋ'

/home/km/projects/symfony-polyfill/tests/Intl/Normalizer/NormalizerTest.php:109

13) Symfony\Polyfill\Tests\Apcu\ApcuTest::testApcu
Polyfills enabled, Failed asserting that false is true.

/home/km/projects/symfony-polyfill/tests/Apcu/ApcuTest.php:27

14) Symfony\Polyfill\Tests\Apcu\ApcuTest::testArrayCompatibility
Polyfills enabled, Failed asserting that false matches expected 'value1'.

/home/km/projects/symfony-polyfill/tests/Apcu/ApcuTest.php:52

15) Symfony\Polyfill\Tests\Apcu\ApcuTest::testAPCUIterator
Polyfills enabled, Failed asserting that false is true.

/home/km/projects/symfony-polyfill/tests/Apcu/ApcuTest.php:71

16) Symfony\Polyfill\Tests\Intl\Normalizer\NormalizerTest::testConstants
Polyfills enabled, Failed asserting that Array &0 (
    'FORM_C' => 4
    'FORM_D' => 2
    'FORM_KC' => 5
    'FORM_KD' => 3
    'NFC' => 4
    'NFD' => 2
    'NFKC' => 5
    'NFKD' => 3
    'NONE' => 1
) is identical to Array &0 (
    'FORM_C' => 16
    'FORM_D' => 4
    'FORM_KC' => 32
    'FORM_KC_CF' => 48
    'FORM_KD' => 8
    'NFC' => 16
    'NFD' => 4
    'NFKC' => 32
    'NFKC_CF' => 48
    'NFKD' => 8
    'NONE' => 2
).

/home/km/projects/symfony-polyfill/tests/Intl/Normalizer/NormalizerTest.php:37

17) Symfony\Polyfill\Tests\Intl\Normalizer\NormalizerTest::testIsNormalized
Polyfills enabled, Failed asserting that true is false.

/home/km/projects/symfony-polyfill/tests/Intl/Normalizer/NormalizerTest.php:53

18) Symfony\Polyfill\Tests\Intl\Normalizer\NormalizerTest::testNormalize
Polyfills enabled, Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'déjà 훈쇼™'
+'déjà 훈쇼™'

/home/km/projects/symfony-polyfill/tests/Intl/Normalizer/NormalizerTest.php:78

FAILURES!
Tests: 1100, Assertions: 364410, Failures: 18, Skipped: 12.

Unsilenced deprecation notices (5)

  5x: Normalizer::NONE is obsolete with ICU 56 and above and will be removed in later PHP versions
    3x in NormalizerTest::testNormalize from Symfony\Polyfill\Tests\Intl\Normalizer
    2x in NormalizerTest::testIsNormalized from Symfony\Polyfill\Tests\Intl\Normalizer

Legacy deprecation notices (136)

There's also a Debian bug report at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911832

[RFC] Apc polyfill

I think it would be useful to have a polyfill for Apc, for the cases that apcu_* functions are available put apc_* is not.

This is the default situation when using Apcu > v5.

The polyfill would mostly be helpful in using older code that relies on apc_* and avoid installing the apcu_bc extension.

It there is agreement that this could be useful I could write it. I imagine it to be basically a complete copy of the Apcu polyfill, but with the u in the opposite place.

I would even be tempted to put it in the same polyfill making it simple to have code work in either situation.

Support ICU 58.1

The current homebrew icu4c package is on version 58.1, while the Symfony intl polyfill package supports 57.1. This results in the following recommendation while running ./bin/symfony_requirements: intl ICU version installed on your system (58.1) does not match the ICU data bundled with Symfony (57.1).

Is it possible to support version 58.1 from icu4c?

is_countable, not Big Endian safe?

Hello, I see a possible endianess issue on is_countable testsuite and latest polyfill release 1.8.0
https://autopkgtest.ubuntu.com/packages/php-symfony-polyfill/cosmic/s390x

Setting up autopkgtest-satdep (0) ...
(Reading database ... 73688 files and directories currently installed.)
Removing autopkgtest-satdep (0) ...
autopkgtest [16:09:03]: test command1: phpunit --bootstrap /usr/share/php/Symfony/Polyfill/autoload.php
autopkgtest [16:09:03]: test command1: [-----------------------
PHPUnit 7.2.7 by Sebastian Bergmann and contributors.

SSS............................................................  63 / 766 (  8%)
............................................................... 126 / 766 ( 16%)
............................................................... 189 / 766 ( 24%)
............................................................... 252 / 766 ( 32%)
............................................................... 315 / 766 ( 41%)
..............................................................S 378 / 766 ( 49%)
SS..F.SSS...................................................... 441 / 766 ( 57%)
............................................................... 504 / 766 ( 65%)
............................................................... 567 / 766 ( 74%)
............................................................... 630 / 766 ( 82%)
............................................................... 693 / 766 ( 90%)
............................................................... 756 / 766 ( 98%)
.....SSS..                                                      766 / 766 (100%)

Time: 2.22 seconds, Memory: 18.22MB

There was 1 failure:

1) Symfony\Polyfill\Tests\Php73\Php73Test::testIsCountable
Failed asserting that false is true.

/tmp/autopkgtest.Lf6G0W/build.nrL/src/tests/Php73/Php73Test.php:27

FAILURES!
Tests: 778, Assertions: 726412, Failures: 1, Skipped: 12.

I'm tempted to disable this part of the testsuite, since php 7.3 is not yet a real thing, and nothing is using is_countable in the archive, and this is a new test... but can you please have a look, or tell me if this is not a real issue?

the architecture is s390x

polyfill-iconv: infinite loop on transliterating U+0096 character

If I try to transliterate the U+0096 character from UTF-8 (0xC2 0x96) to e.g. ASCII, the Iconv::iconv() function hangs due to an infinite loop.

Minimal example:

<?php
require_once('vendor/autoload.php');
use Symfony\Polyfill\Iconv\Iconv;
$text = "the \xC2\x96 character causes problems";
$converted = Iconv::iconv("UTF-8", "ASCII//TRANSLIT", $text);

I have identified that the problem is due to this line.

I tried the following patch, which makes it work and doesn't break any tests, but I don't fully understand how this function works, so it may have unintended consequences.

From 2e8ac7c206166a38526d10bb4df8eaa9c8bdc568 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Koszta=20D=C3=A1niel?= <[email protected]>
Date: Wed, 1 Aug 2018 16:44:38 +0200
Subject: [PATCH] Avoid infinite loop

---
 src/Iconv/Iconv.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/Iconv/Iconv.php b/src/Iconv/Iconv.php
index b9abecb..4d0ebba 100644
--- a/src/Iconv/Iconv.php
+++ b/src/Iconv/Iconv.php
@@ -695,6 +695,8 @@ final class Iconv
                     } else {
                         return false;
                     }
+                } else {
+                    continue;
                 }
 
                 $str = $uchr.substr($str, $i);
-- 
2.18.0

Include stubs from symfony/intl?

I dont understand why symfony/polyfill-intl-icu requires symfony/intl and vice versa.

Shouldnt symfony/polyfill-intl-icu provide all the stubs, making symfony/polyfill-intl-messageformatter obsolete and remove symfony/intl as a polyfill dep.

Effectively symony/intl provides all stubs, except MessageFormatter.

It can be as simple as symfony/polyfill-intl + symfony/intl (specialized lib) no?

gzopen() / gzopen64()

On 32bit builds of Ubuntu 14.04LTS (PHP 5.5.9), three functions are created with the wrong names.
See one of many bug reports.
There seems to be no plans to fix this in Ubuntu, so users of this LTS release cannot use the GZIP library.

Is there a place in this package for the necessary polyfills?

if (!function_exists('gzopen') && function_exists('gzopen64')) {
    function gzopen($filename , $mode = 'r', $use_include_path = 0 ) {
        return gzopen64($filename, $mode, $use_include_path);
    }
}
if (!function_exists('gzseek') && function_exists('gzseek64')) {
    function gzseek($zp , $offset, $whence = SEEK_SET) {
        return gzseek64($zp, $offset, $whence);
    }
}
if (!function_exists('gztell') && function_exists('gztell64')) {
    function gztell($zp) {
        return gztell64($zp);
    }
}

Normalizer::decompose() should check that reordered sequences aren't themselves reordered.

This can be seen using the string "\xe0\xbd\xb6\xe0\xbe\x81", which currently gets decomposed into "\xe0\xbe\xb2\xe0\xbe\x80\xe0\xbd\xb1\xe0\xbe\x80", but the reordered sequences "\xe0\xbe\x80" and "\xe0\xbd\xb1" should themselves be reordered, to give the expected NFD form "\xe0\xbe\xb2\xe0\xbd\xb1\xe0\xbe\x80\xe0\xbe\x80".

I've put in a hacky fix for this on the version of "Normalizer.php" I'm using in the "tl-normalizer" WP plugin fork, which recurses when a reordered sequence has a reordering combining class, see https://github.com/gitlost/tl-normalizer/blob/master/Symfony/Normalizer.php#L237 passim, but I'm sure there's a better way of doing it.

The polyfill should get released

This library is now used as a dependency in Twig 1.23 (and other projects are starting to use it too).
Not having a stable release means that Twig 1.23 is not installable by default in a composer project (you have to change the minimum stability or to require dev versions of symfony/polyfill-mbstring in your project to whitelist it)

APCU polyfill register a class to be autoloadable without taking into account dependency

The \APCUIterator stubs is register to be autoloadable but it extend a class that may very well not exist.
Therfore calling :
class_exists('\APCUIterator');
will trigger a Fatal Error when \APCIterator isnt available.

For exemple, \Stash\Driver\Apc::isAvailable() rely on such a call.

I think, the stubs should only be know by Composer's autoloader if it's instanciable.

polyfill-mbstring should require polyfill-iconv or ext-iconv

The polyfill-mbstring library depends on iconv, but does not require the polyfill-iconv library or ext-iconv. This can be an issue for things such as minimal PHP docker installs that include --configure = --disable-all before listing specific extensions to build.

Note: This is really for the subtree repo as installing the entire polyfill repo would not have this issue. symphony/console only installs polyfill-mbstring.

composer Fatal error Call to undefined function Symfony\Polyfill\Mbstring\iconv()

phar:///usr/local/Cellar/composer/1.0.0-beta1/libexec/composer.phar/vendor/symfony/polyfill-mbstring/Mbstring.php undefined function Symfony\Polyfill\Mbstring\iconv() when called by composer cmd on oxs 10.10.5,I had checked the phar that it had add mbstring/iconv check, How to solve this problem?
Fatal error: Call to undefined function Symfony\Polyfill\Mbstring\iconv() in phar:///usr/local/Cellar/composer/1.0.0-beta1/libexec/composer.phar/vendor/symfony/polyfill-mbstring/Mbstring.php on line 513

Lint check: Fatal error: Cannot declare class CallbackFilterIterator, because the name is already in use

The project fails the PHP lint check. Here are the reproducible steps in the empty folder:

$ composer require symfony/polyfill-php54
...
  - Installing symfony/polyfill-php54 (v1.6.0)
...
$ find vendor -name "*.php" -exec php -l {} ';'
...
No syntax errors detected in vendor/symfony/polyfill-php54/Php54.php
Fatal error: Cannot declare class CallbackFilterIterator, because the name is already in use in vendor/symfony/polyfill-php54/Resources/stubs/CallbackFilterIterator.php on line 28
Errors parsing vendor/symfony/polyfill-php54/Resources/stubs/CallbackFilterIterator.php

I'm using these checks as part of the build for all Composer's libraries to verify whether the files are compatible with my PHP version, however I've got this fatal error instead.

This library was requested by symfony/http-foundation v2.8.32 which was requested by symfony/http-kernel and vipsoft/code-coverage-extension which is used for code coverage tests, so I believe v3.x is not supported yet.

Support APCUIterator for APCu 4.x

APCu Polyfill currently returns early if the legacy APC extension is missing, even though the APCUIterator wrapper is still useful with APCu 4.x (which is the only APCu that works with PHP 5.6).

Zend Server and APC functionality

Zend Server tries to implement compatibility with apc by registering compatibility functions with the same name as the APC functions.

http://files.zend.com/help/Zend-Server-6/content/zend_data_cache_-_configuration_directives.htm

Specifically, the option is "zend_datacache.apc_compatibility". It looks like it gets aliased to zend_shm_cache_store, which mostly works. Unfortunately, it doesn't support the array form of apc_store(), so every call results in errors:

"apc_store() expects parameter 1 to be string, array given"

It looks like this is a problem that other projects have dealt with, and it looks like it's one that's been going on for 8 years or so, so I'm not expecting Zend to fix it anytime soon.

My inclination would be to add a check to see if the parameter to apcu_add() or apcu_store() is an array, and if so to call the apc function individually for each item in the array. It would maintain compatibility with APC, and fix the issues with Zend Server. It's a little bit of a hack, though, and I figured I'd ask before submitting a PR.

Alternatively, I could add support for Zend Data Cache to the Symfony Cache Component.

MessageFormatter should explicitly not support non-English locales

Currently, for plural rules, the MessageFormatter polyfills uses the English rules for all locales (it ignores the locale).
To be consistent with what we do in symfony/intl (used by symfony/polyfill-intl-icu to implement NumberFormatter and DateFormatter), we should rather fail explicitly here (using the English rules for a different locale would not give the right result anyway)

Add support for JSON_THROW_ON_ERROR for the PHP 7.3 polyfill

If feels like it's something that could be provided by the polyfill as well. I can try to do a PR if that's ok.

Note that there is also the exception JsonException missing.

Also the doc for the PHP 7.3 polyfill is outdated, given the entry of the docs for the polyfills, maybe those could be automated somehow to keep them in sync.

mb_convert_case die on specific string

Maximum execution time of 60 seconds exceeded in vendor/symfony/polyfill-mbstring/Mbstring.php on line 183

String of death (urlencoded): d?d???d?d%A6%CC??????d%A1%C0d?d?d%A1%E3

My guess - infinite while cycles

Normalizer::recompose() should reset the last combining class on ASCII.

This can be seen using the string "\xcc\x83\xc3\x92\xd5\x9b", which gets decomposed into "\xcc\x83\x4f\xcc\x80\xd5\x9b". On recompose, $lastUcls isn't reset on the ASCII "\x4f" so the string gets left in this decomposed form instead of the expected NFC normalized "\xcc\x83\xc3\x92\xd5\x9b".

The fix is reset the $lastUcls variable to zero on ASCII, see for instance the version of "Normalizer.php" I'm using in a fork of the WordPress plugin "tl-normalizer" https://github.com/gitlost/tl-normalizer/blob/master/Symfony/Normalizer.php#L184

New release for symfony/polyfill-mbstring

The current release of symfony/polyfill-mbstring has an invalid composer.json scheme. This has already been fixed in the master branch, however this change has not yet been released.

This break the composer validation of dependencies for any projects that has this polyfill included:

symfony/polyfill-mbstring is valid for simple usage with composer but has
strict errors that make it unable to be published as a package:
The property - suggests - is not defined and the definition does not allow additional properties

Could you create a new release including this change.

iconv_substr(): Detected an illegal character in input string

Hello

I have the same error #63

[2016-08-24 15:03:51] lumen.ERROR: ErrorException: iconv_substr(): Detected an illegal character in input string in /var/www/app-storage/vendor/symfony/polyfill/src/Mbstring/Mbstring.php:417
Stack trace:
#0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(8, 'iconv_substr():...', '/var/www/heaven...', 417, Array)
#1 /var/www/app-storage/vendor/symfony/polyfill/src/Mbstring/Mbstring.php(417): iconv_substr('\x01\x00\x00\x00\x00\x01\xE5', 0, 1, 'ASCII')
#2 /var/www/app-storage/vendor/symfony/polyfill/src/Mbstring/bootstrap.php(36): Symfony\Polyfill\Mbstring\Mbstring::mb_substr('\x01\x00\x00\x00\x00\x01\xE5', 0, 1, 'ASCII')
#3 /var/www/app-storage/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(163): mb_substr('\x01\x00\x00\x00\x00\x01\xE5', 0, 1, 'ASCII')

Support APCu 5.x-style increment and decrement

In APCu 4.x, attempting to increment or decrement a key that doesn't exist fails. The workaround is storing a value of 1 or -1 to initialize the key after failing on inc/dec. I'm not sure if it would be part of the mission of this project to support things like that, but it's one of the APCu 4.x vs. 5.x challenges I deal with in LCache (in addition to the iterator).

PHPCompatibility rulesets for the Symfony polyfill-php#.# packages

Hi all,

This is just a "service message".

For those people who use this library and use PHPCompatibility in their CI process, there is now a set of custom rulesets available which can be used to prevent false positives being thrown by PHPCompatibility for the native PHP functionality being polyfilled by the various Symfony polyfill-php#.# packages.

You can find the repo for the Symfony polyfill rulesets here on Github as well as on Packagist.

Hope someone will find it useful 😄

P.S.: If anyone is interested in helping us maintaining the rulesets and/or adding rulesets for the other Symfony polyfill packages, please open an issue in the repo.

intl NumberFormatter

This package could polyfill the NumberFormatter. This is something symfony/intl never tried to do, but what we've mostly accomplished in commerceguys/intl.
We don't try to replicate the rounding behavior, but that could be done, at least partially.

Happy to discuss it via other channels as well.

IMAP extension polyfill

Is anyone aware of a polyfill for thr IMAP extension? Specifically the imap_mime_header_decode function, which is critical to properly decoding email headers.

Replace the extensions

Is it possible to add all the replaced PHP extensions in "replace"? In our case it is the 'mbstring' extension. If a package requires the mbstring extension, and I am installing this package, it should work.

Ref composer/composer#6525

hex2bin() returns false if NUL bytes are in decoded string

hex2bin() returns false if NUL bytes are in decoded string. No error or exception is thrown which breaks code written for PHP 5.4+ that does not explicitly test for this condition, or which uses another test such as preg_match('/^([a-f0-9]{2})*$/', $str).

This breaks binary-safety and is inconsistent with PHP's behavior.

Latest change to bootstrap.php broke composer update process

Not sure if it's me or everyone, but when running composer update with minimum-stability:dev I now receive this error:

Script php aritsan clear-compiled handling the post-update-cmd event returned with an error

[RuntimeException]
  Error Output: PHP Fatal error:  Class 'APCIterator' not found in /path/to/app/vendor/symfony/polyfill-apcu/bootstrap.php on line 32

I'm guessing this has something to do with this recent commit

Increasing the minimum stability bypasses the issue. However, I would like to work in dev stability, is there any workaround or fix?

Iconv polyfill doesn't support //TRANSLIT//IGNORE

Q A
Bug report? yes
Feature request? yes
BC Break report? no

The PHP function iconv() of the iconv extension allows both options to be specified at the same time. However, symfony/polyfill-iconv does not support that.

Example code:

$conv = function ($item) {
    return chr($item);
};

$isoString= implode(array_map($conv, [0x54,0xe4,0x73,0x74,0xdf]));

var_dump(iconv('ISO-8859-1', 'ASCII//IGNORE', $isoString));
var_dump(iconv('ISO-8859-1', 'ASCII//TRANSLIT', $isoString));
var_dump(iconv('ISO-8859-1', 'ASCII//TRANSLIT//IGNORE', $isoString));

Expected output (as with glibc iconv 2.19):

string(3) "Tst"
string(6) "Tastss"
string(6) "Tastss"

Actual output:

string(3) "Tst"
string(6) "Tastss"
PHP Notice:  iconv(): Wrong charset, conversion from `iso-8859-1' to `ascii//translit' is not allowed in /home/user/pdfparser/vendor/symfony/polyfill-iconv/Iconv.php on line 176
bool(false)

Tested with:

  • symfony/polyfill-iconv (v1.5.0)
  • symfony/polyfill-iconv (dev-master 1ea0e08)

mb_strlen exists but mb_check_encoding undefined

Hi. I trying to use this amazing library in my work but still not understand what happens. I manually disable mbstring module in my php-7 setup for testing purposes. But all of this functions from this library still not defined.

I debug into the bootstrap.php and see that function_exists('mb_strlen') returns true. I hope that I'm doing something wrong but I can't explain that happening.

Why mb_strlen() defined if mbstring module is disabled?

$exists = function_exists('mb_strlen');
(bool)true

$phpVersion = phpversion();
7.0.12-1+deb.sury.org~trusty+1

$extensions = get_loaded_extensions();
array (
  0 => 'Core',
  1 => 'date',
  2 => 'libxml',
  3 => 'openssl',
  4 => 'pcre',
  5 => 'zlib',
  6 => 'filter',
  7 => 'hash',
  8 => 'Reflection',
  9 => 'SPL',
  10 => 'session',
  11 => 'standard',
  12 => 'cgi-fcgi',
  13 => 'mysqlnd',
  14 => 'PDO',
  15 => 'xml',
  16 => 'bcmath',
  17 => 'calendar',
  18 => 'ctype',
  19 => 'curl',
  20 => 'dom',
  21 => 'exif',
  22 => 'fileinfo',
  23 => 'ftp',
  24 => 'gd',
  25 => 'gettext',
  26 => 'iconv',
  27 => 'imagick',
  28 => 'imap',
  29 => 'json',
  30 => 'mcrypt',
  31 => 'memcache',
  32 => 'mysqli',
  33 => 'pdo_mysql',
  34 => 'Phar',
  35 => 'posix',
  36 => 'readline',
  37 => 'shmop',
  38 => 'SimpleXML',
  39 => 'soap',
  40 => 'sockets',
  41 => 'ssh2',
  42 => 'sysvmsg',
  43 => 'sysvsem',
  44 => 'sysvshm',
  45 => 'tokenizer',
  46 => 'wddx',
  47 => 'xmlreader',
  48 => 'xmlwriter',
  49 => 'xsl',
  50 => 'zip',
  51 => 'Zend OPcache',
  52 => 'xdebug',
)

mb_strlen: iconv_strlen triggering notice in certain situations

As suggested by @stof in php-amqplib/php-amqplib#72 (comment), I'm opening this ticket.

I can't really tell how to replicate this - I ran into it when installing RabbitMQ and not having mbstring extension installed.

Seems like theres being passed an "illegal" character in the string and its not being considered. This triggers a Notice, and in RabbitMQ case, it throws an exception.

PHP Notice:  iconv_strlen(): Detected an illegal character in input string in …/vendor/symfony/polyfill-mbstring/Mbstring.php on line 338
    public static function mb_strlen($s, $encoding = null)
    {
        $encoding = self::getEncoding($encoding);
        var_dump($s);

        return iconv_strlen($s, $encoding);
    }
string(14) "\000\000\000\000�\000
\000
\000    \000"

Installing the mbstring module prevents RabbitMQ from throwing the Exception, which I guess means this polyfill method is not really replacing the module (?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.