Skip to content

Conversation

@ondrejmirtes
Copy link
Member

No description provided.

Added comprehensive documentation clarifying the important differences
between string and char types in Zephir:

**Key Additions:**

1. **Type System Section Enhancements:**
   - Clarified that char uses single-quote syntax: 'A'
   - Emphasized that string indexing (str[i]) returns char, not string
   - Added that string must use double-quote syntax: "hello"
   - Noted that single quotes are exclusively for char type

2. **New Dedicated Section: "String vs Char: Key Distinctions":**
   - Syntax difference table (single vs double quotes)
   - Detailed explanation of array access returning char
   - Practical examples showing string iteration yields char types
   - Type conversion examples (char to string and vice versa)
   - Common pitfall example showing incorrect char/string comparison

3. **Coding Guidelines Update:**
   - Added reminder that string indexing returns char type
   - Emphasized quote usage: single for char, double for string

4. **Common Pitfalls Section:**
   - Added "String vs Char Confusion" as item #3
   - Listed specific gotchas:
     * str[0] is char type, not string
     * Quote syntax requirements
     * Loop variable type when iterating strings
     * Correct comparison syntax

This addresses a critical type distinction that can cause confusion
for developers new to Zephir, especially those coming from PHP where
this distinction doesn't exist.
@ondrejmirtes ondrejmirtes merged commit 1e718d7 into 2.1.x Dec 30, 2025
112 of 116 checks passed
@ondrejmirtes ondrejmirtes deleted the claude/char-string-docs-Rg8iA branch December 30, 2025 17:50
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.

2 participants