Skip to content

[4.x] Document the real types of escape() and quote() and deprecate other input - #415

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-escape-quote-types
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-escape-quote-types

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

escape() is documented as returning string, but every driver returns integer input unchanged. quote() is documented for array|string, but scalars of every kind are passed to it everywhere. Callers and static analysis cannot rely on the declared types.

  • The DatabaseInterface::escape() and quote() docblocks (and DatabaseDriver::quote()) now state the actual types: escape(string|int|float): string|int, and quote() accepts a scalar, null or an array of those.
  • Passing anything else to quote() – an object without __toString(), a resource – now triggers trigger_deprecation('joomla/database', …). In 5.0 native parameter types will reject it. The check lives in a new protected DatabaseDriver::checkQuoteInput(), which SqlsrvDriver::quote() calls as well, because it overrides quote() for scalars.

No behaviour changes for supported input.

Testing Instructions

New Tests/Sqlite/QuoteDeprecationTest.php (no server needed; vendor/bin/phpunit Tests/Sqlite/QuoteDeprecationTest.php): strings, integers and arrays raise nothing, and a resource raises one deprecation. It fails before the change.

Documentation Changes Required

None on 4.x-dev. #373's docs/overview.md and docs/parameters-and-escaping.md ("escape() returns mixed types") already describe the int return. Once both PRs are merged, they could add that non-scalar input to quote() is deprecated. The native types for 5.0 are not part of this PR.

🤖 Generated with Claude Code

…nput

escape() is documented as returning a string but returns integers unchanged,
and quote() accepts arrays as well as scalars. The docblocks now state the
actual union types. Passing anything else to quote(), such as an object
without __toString() or a resource, triggers a deprecation, preparing the
native types planned for 5.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant