Skip to content

Commit eadaa38

Browse files
nanasessclaude
andcommitted
docs: README の比較表に symfony/polyfill-php84 を追加、phpstan の既存エラーを解消
- Key Differences 表を3者比較 (phpseclib/bcmath_compat, symfony/ polyfill-php84, bcmath-polyfill) に拡張。拡張非依存性・bcdivmod・ 全RoundingMode対応・純粋enum・丸め方式の違いを明記 - 古くなった「RoundingMode Enum Limitations」節を削除 (全モード対応済み) - PHP 8.1 の phpstan が in_array を常に true と誤判定する既存エラー (main でも failure) を ignore。bcpow を2引数目テストから除外する 意図的ガードのため該当コードは維持 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7a3eab6 commit eadaa38

2 files changed

Lines changed: 34 additions & 28 deletions

File tree

README.md

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,34 +219,33 @@ While the polyfill is significantly slower than native bcmath:
219219
- PHP >= 7.3.0: Use `bcscale()` without arguments
220220
- PHP < 7.3.0: Use `max(0, strlen(bcadd('0', '0')) - 2)`
221221

222-
### RoundingMode Enum Limitations
223-
- Three `RoundingMode` enum values are not yet implemented:
224-
- `RoundingMode::TowardsZero` - Will throw `ValueError`
225-
- `RoundingMode::AwayFromZero` - Will throw `ValueError`
226-
- `RoundingMode::NegativeInfinity` - Will throw `ValueError`
227-
- These modes are planned for implementation in a future release
228-
- Use traditional `PHP_ROUND_*` constants as alternatives when needed
229-
230-
## 🔄 Key Differences from phpseclib/bcmath_compat
231-
232-
| Feature | phpseclib/bcmath_compat | bcmath-polyfill |
233-
|---------------------------|--------------------------------|-------------------------------------|
234-
| **PHP 8.4 functions** | ❌ Not supported | ✅ Full support |
235-
| `bcfloor()` |||
236-
| `bcceil()` |||
237-
| `bcround()` |||
238-
| **RoundingMode enum** | ❌ Not supported | ✅ Partial (4/7 modes) |
239-
| `HalfAwayFromZero` |||
240-
| `HalfTowardsZero` |||
241-
| `HalfEven` |||
242-
| `HalfOdd` |||
243-
| `TowardsZero` || ⏳ Planned |
244-
| `AwayFromZero` || ⏳ Planned |
245-
| `NegativeInfinity` || ⏳ Planned |
246-
| **PHP 8.2+ deprecations** | ⚠️ Warnings | ✅ Fixed |
247-
| **Test suite pollution** | ⚠️ Issues | ✅ Fixed |
248-
| **Active maintenance** | ❌ Limited | ✅ Active |
249-
| **CI/CD (PHP versions)** | GitHub Actions (8.1, 8.2, 8.3) | GitHub Actions (8.1, 8.2, 8.3, 8.4, 8.5) |
222+
## 🔄 Key Differences from phpseclib/bcmath_compat and symfony/polyfill-php84
223+
224+
The three libraries target different goals. `phpseclib/bcmath_compat` is the classic pre-8.4 polyfill.
225+
`symfony/polyfill-php84` backports **only** the new PHP 8.4 functions and activates them **only when the
226+
native bcmath extension is already loaded**. `bcmath-polyfill` provides the complete bcmath API —
227+
including the PHP 8.4 additions — for environments **with or without** the extension.
228+
229+
| Feature | phpseclib/bcmath_compat | symfony/polyfill-php84 | bcmath-polyfill |
230+
|------------------------------------------------|--------------------------------|---------------------------------|------------------------------------------|
231+
| Classic bc functions (`bcadd`, `bcmul`, …) || ❌ Not provided ||
232+
| Works **without** the bcmath extension || ❌ Requires the extension ||
233+
| `bcfloor()` / `bcceil()` / `bcround()` || ✅ (extension required) ||
234+
| `bcdivmod()` || ✅ (delegates to native bc) | ✅ (works without the extension) |
235+
| **RoundingMode enum** (all 8 modes) ||||
236+
| Arbitrary-precision rounding (no float fallback)|| ✅ (pure string algorithm) | ✅ (pure string algorithm) |
237+
| `RoundingMode` is a *pure* enum (native shape) ||||
238+
| Implementation of rounding || Pure string digits | Pure string digits (phpseclib elsewhere) |
239+
| Extra dependency | phpseclib | none | phpseclib |
240+
| **PHP 8.2+ deprecations** | ⚠️ Warnings | ✅ Fixed | ✅ Fixed |
241+
| **Active maintenance** | ❌ Limited | ✅ Active | ✅ Active |
242+
| **CI/CD (PHP versions)** | GitHub Actions (8.1, 8.2, 8.3) | 7.2+ | GitHub Actions (8.1, 8.2, 8.3, 8.4, 8.5) |
243+
244+
> When `bcmath-polyfill` and `symfony/polyfill-php84` are installed together on an environment that has
245+
> the bcmath extension and runs PHP 8.2/8.3, both declare `bcceil()`/`bcfloor()`/`bcround()` and whichever
246+
> autoloads first wins (guarded by `function_exists()`, so no fatal redeclaration). Because this package's
247+
> rounding uses a native-compatible string algorithm, the results are identical either way. See
248+
> [Interoperability with `symfony/polyfill-php84`](#interoperability-with-symfonypolyfill-php84).
250249
251250
### Migration from phpseclib/bcmath_compat
252251

phpstan.neon.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ parameters:
6161
identifier: property.nonObject
6262
path: tests/BCMathTest.php
6363
message: "#Cannot access property \\$name on string\\.#"
64+
# On PHP 8.1 PHPStan narrows $function to the six non-pow operations and
65+
# reports this in_array() guard as always-true, while PHP 8.5 does not.
66+
# The guard deliberately excludes bcpow() from the second-argument check,
67+
# so it must stay. Pre-existing on main; ignored to keep the 8.1 matrix green.
68+
-
69+
path: tests/BCMathTest.php
70+
message: "#Call to function in_array\\(\\) with arguments .* and true will always evaluate to true\\.#"

0 commit comments

Comments
 (0)