WordPress / WordPress/WordPress-Coding-Standards
$wpdb->(insert|update|delete|replace)() return value shouldn't be used in boolean comparisons
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
The return value will be an integer, and -1 can indicate an error as well as 0. So comparing to a boolean value will mean that errors won't be detected in all cases, since -1 == true.
An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records were updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error. 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is identified in the issue. Start by locating the rules that inspect $wpdb->insert(), update(), delete(), and replace() calls, then determine how boolean comparisons are detected. Done means comparisons that can hide a -1 error are reported, with tests covering affected-row values and error handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100