Skip to content

[Bug] Numeric-string indexes are rejected for string offset access #197

@nahime0

Description

@nahime0

Description

PHP accepts numeric-string indexes for string offset access (for example "0" and "3"), coercing them the same way it does integer offsets. elephc rejects the same code at compile time with String index must be integer.

This is a PHP compatibility issue.

Reproduction

<?php
$s = "abc";
echo $s['0'];
echo "\n";
echo isset($s['3']) ? "y\n" : "n\n";

PHP output

a
n

elephc behavior

Compilation fails with:

error[3:8]: String index must be integer
error[5:14]: String index must be integer

Expected behavior

The program should compile and behave like PHP:

  • $s['0'] should produce "a"
  • isset($s['3']) should produce false

Actual behavior

elephc rejects numeric-string offsets instead of accepting PHP's coercion rules for string indexes.

Environment

  • elephc 0.21.14
  • PHP 8.4.20
  • macOS ARM64

Notes

This looks like a type-checker restriction on string-offset indexing rather than a runtime issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingphp-compatibilityPHP compatibility / deviation from PHP behaviorstringsString handling and literalstype-checkerStatic type checker / inference issues

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions