Accessing string offsets
| From: | Markus Fischer | Date: | Sun, 11 Nov 2001 13:02:35 +0000 |
| Subject: | Accessing string offsets | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-70100@lists.php.net to get a copy of this message | ||
Right now, the following produces a warning when using
error_reporting(E_ALL) which can only be catched with ob_start():
<?
$string = "foo";
echo $string[3] . "\n";
?>
gives
-(1) : Warning - Uninitialized string offset: 3
Is it really necessary to always first check the length before
accessing a certain offset? Wouldn't just returning an empty
string be enough? I.e., just remove the warning in
Zend/zend_execute.c:103 ?
Btw, is $string{$offset} documented anywhere? Derick already told
me its not but then its in PHP since a long time. Is $string{$offset}
really faster but not well-tested? I've already even seen it in a
PEAR package (Console/Getopt.php from Andrei).
- Markus