Date: 11/14/99
- Next message: Joey: "Re: [PHP-DEV] Re: Bug #1964 Updated: Every time I load document, I get a message "document contains no data""
- Previous message: bobhitt <email protected>: "[PHP-DEV] Bug #2725: Fatal error: Call to undefined function: odbc_connect()"
- Next in thread: Joey: "Re: [PHP-DEV] Re: [PHP4BETA] <?$a="1";$a[0]=1;?> cause mem-block overrun."
- Reply: Joey: "Re: [PHP-DEV] Re: [PHP4BETA] <?$a="1";$a[0]=1;?> cause mem-block overrun."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-dev people, please read this mail!
At 02:25 PM 11/13/99 -0800, Lars Torben Wilson wrote:
>Thies C. Arntzen writes:
> > i know - i've reported this one a few times - but i haven't gotten any
> > reply on it yet...
> >
> > andi, zeev - this is something that only you can fix i persume?
> >
> > ..verified with latest CVS
> >
> > tc
>
>BTW, what is the core statement on what this should do? There's an
>open doc bug report that I'd like to close on this; I'd just like to
>make sure that I document the expected behaviour correctly:
>
><?php
>$a = 1;
>echo "$a, ";
>
>$a[0] = 'Hello';
>echo "'$a[0]'";
>?>
>
>In PHP 3.0.13-dev, I get:
>
>1
>Warning: Variable $a is not an array or string in
>/home/torben/public_html/php3test/__phplist.html on line 16
>'1'
>
>
>In PHP 4.0B3-RC4, I get:
>
>1, ''
>
>
>Now, it has been argued that treating $a as an array should
>automatically convert it to an array (i.e., the above should print
>"1, 'Hello'" (after which, presumably, echo $a would output the normal
>'Array').
>
>Could someone finalize the expected behaviour for me so it can go in
>the manual?
What you have brought up is not really a problem with compatibility. It's a
much deeper problem with string offsets and arrays.
What should really happen when $a is a simple value and then you use $a as
an array is one of two things:
a) Convert $a to an array which would make it's value index 0 of that array
similar to the (array) casting operator.
b) Always convert $a to an empty array.
We would probably go with (a) however this brings up another problem and
ambiguity.
In a similar example to yours:
<?
$a = 1;
$a[0] = "f";
?>
$a[0] would end up holding the string "f".
However if the example where:
<?
$a="1";
$a[0] = "f";
?>
Then there would be an ambiguity with string offsets. Would you want $a to
end up being the string "f" or would you want $a to be an array with it's
0th index the string "f".
We support string offsets in PHP 4 for backwards compatibility issues but
the way they share the same notation with array offsets is "not the right
thing". It creates ambiguity and is bad design.
What I'm thinking of doing is separate these two notations before the
release of PHP 4. Maybe add {} for string offsets so you'd do $a{0} when
you mean string offset and $a[0] when you mean array offset. We would only
document {} as string offset support and encourage people to migrate to
this version. In a few months, maybe with PHP 4.1 we would deprecate the
old notation so that the language could be correct and unambiguous.
Some people might not like this but it really is the best way to go for
PHP. Having the core language contain such a bad design issue in it would
not look good to professionals. If we add this to the release notes of PHP
4 telling people to convert to the new syntax it would cause very little
headaches later on.
Andi
--- Andi Gutmans <andi <email protected>> http://www.zend.com/-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Joey: "Re: [PHP-DEV] Re: Bug #1964 Updated: Every time I load document, I get a message "document contains no data""
- Previous message: bobhitt <email protected>: "[PHP-DEV] Bug #2725: Fatal error: Call to undefined function: odbc_connect()"
- Next in thread: Joey: "Re: [PHP-DEV] Re: [PHP4BETA] <?$a="1";$a[0]=1;?> cause mem-block overrun."
- Reply: Joey: "Re: [PHP-DEV] Re: [PHP4BETA] <?$a="1";$a[0]=1;?> cause mem-block overrun."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

