undefined are defined |
|
|
||||||||||||
|
Site Admin
|
oh, common!
it's how php interprets string elements. No bugs, at least in the debugger Check the code below:
it will print '4' |
||||||||||||||
|
|
perhaps .... actually ... yes but i did not expect there this
to be honest i did not know that string can be used as an index of other string ... sorry regards. |
||||||||||||
|
Site Admin
|
I'm not sure but seems it works this way:
echo $vvvv['v']; php takes 'v' and converts it to integer, seems it gets 0, then character under index 0 ($vvvv[0]) is echoed. At least I see no other reasons for the '4' in the output. |
||||||||||||
|
|
The following information can be found under Types:Strings in the PHP manual:
String conversion to numbers When a string is evaluated as a numeric value, the resulting value and type are determined as follows. The string will evaluate as a float if it contains any of the characters '.', 'e', or 'E'. Otherwise, it will evaluate as an integer. The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits. |
||||||||||||
|
Site Admin
|
aha, exponent is extremely useful. Seems, from php gurus perspectives, people often use strings of more than (2E+31) characters and therefore it's clear that 32bit integers are insufficient for addressing them...
Nevertheless I'd expect at least a notice issued when such index as 'v' is used, but seems nobody cares... |
||||||||||||
|
|
Well, this is of course not limited to array indexing. PHP has always included implicit conversion from string to number. Most scripting languages do. One important use for this is to use data from form fields or arguments passed in an url without explicitly having to cast it to int or float.
|
||||||||||||
|
Site Admin
|
yes, it's known and I'd have nothing against '0' to be used as 0
Even more, I'm not against 'v' to be used as 0. All I'm against is the silent way it converts non-integers to integers |
||||||||||||
|
undefined are defined |
|
||
Content © NuSphere Corp., PHP IDE team
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by