Fix str_repeat() float argument in xPDOGenerator::varExport()#274
Open
opengeek wants to merge 1 commit intomodxcms:3.xfrom
Open
Fix str_repeat() float argument in xPDOGenerator::varExport()#274opengeek wants to merge 1 commit intomodxcms:3.xfrom
opengeek wants to merge 1 commit intomodxcms:3.xfrom
Conversation
JoshuaLuckers
approved these changes
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
xPDOGenerator::varExport()used integer division via/to compute the indent level passed tostr_repeat(). When the internal$spacescounter is odd (which happens at any nesting depth wherevar_export()produces a line with an odd number of leading spaces), the expression$spaces / 2yields a float. PHP 8.1 introduced a deprecation notice for implicit float-to-int casts, so every nested array exported through the generator emitted:The fix replaces
$spaces / 2withintdiv($spaces, 2), which performs integer division without producing a float.intdiv()has been available since PHP 7.0, well within the project minimum.Files and methods changed
src/xPDO/Om/xPDOGenerator.php—varExport()(static), line 129:$spaces / 2replaced withintdiv($spaces, 2).test/xPDO/Test/Om/xPDOGeneratorTest.php— new test file (2 test methods).test/sqlite.phpunit.xml,test/mysql.phpunit.xml,test/pgsql.phpunit.xml,test/complete.phpunit.xml— new test file registered in theCompletetestsuite block of each config.Cross-driver impact
xPDOGeneratoris a code-generation utility invoked during schema-to-model compilation (i.e., when a developer runsxPDO::loadPackage()or the generator CLI to produce PHP class files from an XML schema). It is not involved at query time or in the ORM runtime path. The deprecation therefore surfaces during development and build workflows, not in production request handling. All four driver configs (MySQL, PostgreSQL, SQLite, complete) were updated because the generator is driver-agnostic — the affected method has no driver-specific branches.Test coverage
New file:
test/xPDO/Test/Om/xPDOGeneratorTest.phptestVarExportNestedArrayOddSpacesProducesNoDeprecation— installs anE_DEPRECATEDerror handler before callingvarExport()with a two-level nested array (which guarantees an odd$spacesvalue), then asserts no float deprecation message was captured. This test failed before the fix and passes after.testVarExportNestedArrayReturnsString— asserts thatvarExport()returns a non-empty string beginning witharray (for the same nested input, confirming output correctness is not affected by the fix.Full suite result after fix (sqlite config): Tests: 432, Assertions: 599, Skipped: 1 — zero failures.
Breaking change assessment
This is a pure internal implementation fix.
varExport()is a protected static method with no public API contract. The method signature is unchanged. Return values are identical —intdiv($n, 2)produces the same integer result as(int)($n / 2)for all non-negative integers. No callers outside the class are affected. This change is safe to include in a patch release.Contributors
No external contributor prompted this fix. It was identified internally during 3.x release preparation while auditing PHP 8.1 deprecation notices across the codebase.