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
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.
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 withString index must be integer.This is a PHP compatibility issue.
Reproduction
PHP output
elephc behavior
Compilation fails with:
Expected behavior
The program should compile and behave like PHP:
$s['0']should produce"a"isset($s['3'])should producefalseActual behavior
elephc rejects numeric-string offsets instead of accepting PHP's coercion rules for string indexes.
Environment
Notes
This looks like a type-checker restriction on string-offset indexing rather than a runtime issue.