Skip to content

Conversation

@ondrejmirtes
Copy link
Member

Added critical documentation about converting PHP strings to Zephir:

Key Addition:
When converting PHP code to Zephir, all single-quoted strings must be converted to double-quoted strings and properly escaped following the same escape rules as double-quoted strings in PHP.

Why This Matters:

  • In PHP: Both 'text' and "text" create strings
  • In Zephir: 'x' creates a char, "text" creates a string
  • Single quotes in Zephir are exclusively for single characters (char type)

Changes Made:

  1. Dynamic Types Section:

    • Added note that strings must use double quotes (unlike PHP)
    • Added "PHP to Zephir" conversion reminder
  2. String vs Char Section:

    • Added dedicated "Important for PHP to Zephir Conversion" subsection
    • Provided side-by-side PHP vs Zephir code examples
    • Showed escape sequence handling differences
  3. Common Pitfalls:

    • Added conversion reminder to string vs char confusion item

This prevents a common mistake when porting PHP code to Zephir where developers might try to use single quotes for strings, which would create char types instead.

Added critical documentation about converting PHP strings to Zephir:

**Key Addition:**
When converting PHP code to Zephir, all single-quoted strings must be
converted to double-quoted strings and properly escaped following the
same escape rules as double-quoted strings in PHP.

**Why This Matters:**
- In PHP: Both 'text' and "text" create strings
- In Zephir: 'x' creates a char, "text" creates a string
- Single quotes in Zephir are exclusively for single characters (char type)

**Changes Made:**

1. **Dynamic Types Section:**
   - Added note that strings must use double quotes (unlike PHP)
   - Added "PHP to Zephir" conversion reminder

2. **String vs Char Section:**
   - Added dedicated "Important for PHP to Zephir Conversion" subsection
   - Provided side-by-side PHP vs Zephir code examples
   - Showed escape sequence handling differences

3. **Common Pitfalls:**
   - Added conversion reminder to string vs char confusion item

This prevents a common mistake when porting PHP code to Zephir where
developers might try to use single quotes for strings, which would
create char types instead.
@ondrejmirtes ondrejmirtes merged commit 3916263 into 2.1.x Dec 30, 2025
111 of 116 checks passed
@ondrejmirtes ondrejmirtes deleted the claude/char-string-docs-Rg8iA branch December 30, 2025 17:57
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