find-logic-errors
Detects logic errors in PHP code. Finds incorrect conditions, wrong operators, missing switch cases, inverted logic, short-circuit evaluation issues.
Best use case
find-logic-errors is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Detects logic errors in PHP code. Finds incorrect conditions, wrong operators, missing switch cases, inverted logic, short-circuit evaluation issues.
Teams using find-logic-errors should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/find-logic-errors/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How find-logic-errors Compares
| Feature / Agent | find-logic-errors | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Detects logic errors in PHP code. Finds incorrect conditions, wrong operators, missing switch cases, inverted logic, short-circuit evaluation issues.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Logic Error Detection
Analyze PHP code for logic errors that cause incorrect behavior.
## Detection Patterns
### 1. Incorrect Comparison Operators
```php
// BUG: Assignment instead of comparison
if ($status = 'active') { } // Should be ===
// BUG: Wrong comparison type
if ($count == '0') { } // '0' is truthy in string comparison
// BUG: Yoda condition error
if ('active' = $status) { } // Assignment error
```
### 2. Inverted Logic
```php
// BUG: Double negation confusion
if (!$user->isNotActive()) { } // Hard to reason about
// BUG: Wrong negation placement
if (!$a && $b) { } // vs if (!($a && $b))
// BUG: DeMorgan's law violation
if (!$a || !$b) { } // When meaning !($a && $b)
```
### 3. Missing Switch/Match Cases
```php
// BUG: Missing enum case
match ($status) {
Status::Active => 'active',
Status::Inactive => 'inactive',
// Missing: Status::Pending, Status::Deleted
};
// BUG: Missing default
switch ($type) {
case 'A': return 1;
case 'B': return 2;
// No default - undefined behavior for other values
}
```
### 4. Short-Circuit Evaluation Issues
```php
// BUG: Side effect in short-circuit
if ($valid && $this->save()) { } // save() not called if !$valid
// BUG: Order matters
if ($obj->method() && $obj !== null) { } // Null check too late
```
### 5. Off-by-One in Comparisons
```php
// BUG: Fence post error
if ($index < count($array)) { } // vs <=
// BUG: Wrong boundary
for ($i = 0; $i <= $length; $i++) { } // Off by one
```
### 6. Boolean Expression Errors
```php
// BUG: Always true/false
if ($age > 0 || $age <= 0) { } // Always true
// BUG: Unreachable condition
if ($x > 10 && $x < 5) { } // Always false
// BUG: Redundant condition
if ($status === 'active' && $status !== 'inactive') { } // Second part redundant
```
### 7. Return Value Ignorance
```php
// BUG: Ignoring important return
array_push($items, $new); // Returns count, not array
$string->trim(); // String is immutable, returns new string
```
## Grep Patterns
```bash
# Assignment in condition
Grep: "if\s*\([^=]*[^!=<>]=[^=][^)]*\)" --glob "**/*.php"
# Double negation
Grep: "!\$\w+->isNot|!!\$" --glob "**/*.php"
# Empty switch without default
Grep: "switch\s*\([^)]+\)\s*\{[^}]*\}" --glob "**/*.php"
```
## Output Format
```markdown
### Logic Error: [Description]
**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Incorrect Operator|Inverted Logic|Missing Case|...]
**Issue:**
[Description]
**Code:**
```php
// Current code
```
**Fix:**
```php
// Corrected code
```
```Related Skills
find-type-issues
Detects type issues in PHP code. Finds implicit type coercion, mixed types in comparisons, unsafe casting, type mismatches in returns.
find-resource-leaks
Detects resource leaks in PHP code. Finds unclosed file handles, database connections not released, streams not freed, missing finally blocks, temporary files not cleaned.
find-race-conditions
Detects race conditions in PHP code. Finds shared mutable state, check-then-act patterns, TOCTOU vulnerabilities, concurrent modification issues.
find-null-pointer-issues
Detects null pointer issues in PHP code. Finds property/method access on null, missing null checks, nullable returns without handling, optional chaining gaps.
find-infinite-loops
Detects infinite loop risks in PHP code. Finds missing break conditions, incorrect loop variables, unbounded recursion, circular references.
find-exception-issues
Detects exception handling issues in PHP code. Finds swallowed exceptions, generic catches, missing exception handling, re-throwing without context, exception in finally.
find-boundary-issues
Detects boundary issues in PHP code. Finds array index out of bounds, empty collection access, off-by-one errors, integer overflow, string length issues.
bug-root-cause-finder
Root cause analysis methods for PHP bugs. Provides 5 Whys technique, fault tree analysis, git bisect guidance, and stack trace parsing.
analyze-docker-runtime-errors
Analyzes Docker runtime errors for PHP containers. Identifies 502 Bad Gateway, OOM kills, connection refused, and permission issues.
analyze-docker-build-errors
Analyzes Docker build errors for PHP projects. Identifies extension compilation failures, dependency issues, memory limits, and provides fixes.
yii-knowledge
Yii framework knowledge base. Provides Yii3 modular architecture, DDD integration, PSR-7/PSR-15 compliance, persistence, DI, security (RBAC, auth), event system (PSR-14), queue/jobs, infrastructure components (cache, rate limiter, HTTP client), testing, and antipatterns for Yii PHP projects.
troubleshooting-template
Generates troubleshooting guides and FAQ sections for PHP projects. Creates problem-solution documentation.