# $a{} stuff

- Thread: https://externals.io/message/6777
- Original archive: https://news-web.php.net/php.internals/6777
- Started by Derick Rethans on 2004-01-03T21:35:51+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #6777 — Derick Rethans — 2004-01-03T21:35:51+00:00

URL: https://externals.io/message/6777#6777

Hello,

due to a little discussion on IRC I noticed that the following code
works:

<?php
	$a = "foobar";
	$a{strlen($a)-1};
?>

now IMO the offset should only be a simple integer value, as this is a
little bit too much magic to me (and perlish). Although the code above
can have it's use, the following does also work fine:

file1.php
<?php
	return 4;
?>

file2.php
<?php
	$a = "foobar";
	echo $a{include 'file1.php'};
?>

echos 'a'.

I think this sideeffect should be disallowed as it adds a lot of
unreadableness to code. (I do als vagely remember a discussion a year or
something ago which resulted in something like "the offset to a string
should be an integer only, and not for example {1..4} or {-1}". Can't
find this though in the archives.

regards,
Derick

---

## #6778 — Rasmus Lerdorf — 2004-01-03T21:40:35+00:00

URL: https://externals.io/message/6777#6778 · In reply to: #6777

> I think this sideeffect should be disallowed as it adds a lot of
> unreadableness to code. (I do als vagely remember a discussion a year or
> something ago which resulted in something like "the offset to a string
> should be an integer only, and not for example {1..4} or {-1}". Can't
> find this though in the archives.

That's a different argument.  {1..4} and {-1} both introduce new concepts.  
I see no reason why {} cannot contain exactly the same things that [] can 
contain today.  And if suddenly [] could only contain integers pretty much 
every PHP script I have ever written would break.  The whole point of {} 
is to explicitly differentiate an string index from an array index.  How 
that index is specified inside the braces shouldn't differ from one to the 
other.

-Rasmus

---

## #6779 — Edin Kadribasic — 2004-01-03T21:43:23+00:00

URL: https://externals.io/message/6777#6779 · In reply to: #6777

On Saturday, Jan 3, 2004, at 22:35 Europe/Copenhagen, Derick Rethans 
wrote:

> Hello,
>
> due to a little discussion on IRC I noticed that the following code
> works:
>
> <?php
> 	$a = "foobar";
> 	$a{strlen($a)-1};
> ?>
>
> now IMO the offset should only be a simple integer value, as this is a
> little bit too much magic to me (and perlish).

What is a "simple integer value"? You mean only to allow integer 
constants here? How are you supposed to process a string char by char 
without some sort of calculation of string offset?

Edin
