Re: cvs: php4 /pear/scripts pear.in
| From: | (Stig Sæther Bakken) | Date: | Wed, 23 May 2001 12:18:48 +0000 |
| Subject: | Re: cvs: php4 /pear/scripts pear.in | ||
| References: | 1 2 3 | Groups: | php.pear.cvs |
| Request: | Send a blank email to pear-cvs+get-178@lists.php.net to get a copy of this message | ||
["Tomas V.V.Cox" <cox@idecnet.com>]
> Stig Sæther Bakken wrote:
> >
> > ["Thomas V.V.Cox" <cox@idecnet.com>]
> > > + if ($param[0] != DIRECTORY_SEPARATOR) {
> >
> > I think $param{0} is the correct syntax here (although the above
> > works, it's not recommended).
> >
>
> Sorry Stig, I don't understand you here. $param is a string and
> $param[0] is the first char, why use "{}"? I thought that {} was only
> for escape vars inside a string.
>
> This is documented in the manual language.types.string.html:
> /* Get the first character of a string */
> $str = 'This is a test.';
> $first = $str[0];
This syntax is ambiguous; $str may be an array or a string, and PHP
has to evaluate the difference at execution time. If you do
$first = $str{0};
..the parser knows at compile time that $str is a string and you want
a character index.
The {} characters are used inside double-quoted strings too, but
that's fine, the syntax is still unambiguous.
- Stig
--
Stig Sæther Bakken <ssb@fast.no>
Fast Search & Transfer ASA, Trondheim, Norway