NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
undefined are defined


Joined: 09 Jul 2006
Posts: 15
Reply with quote
Hello.
Here are two screens:




Please look on $element[$keyname]['v'], why there is 'P' string when I know that there is no ['v'] key in my variable $element[$keyname],

affected phped version: 4.6.4620

p.s.
by the way please add wrapping long strings in tooltips and watch/variables windows, this is must have feature!
View user's profileFind all posts by ppvSend private message


Joined: 09 Jul 2006
Posts: 15
Reply with quote
one more screenshot:
View user's profileFind all posts by ppvSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
oh, common!
it's how php interprets string elements.
No bugs, at least in the debugger Smile

Check the code below:

Code:
   $vvvv = '40';
   echo $vvvv['v'];

it will print '4' Smile Smile Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 09 Jul 2006
Posts: 15
Reply with quote
perhaps .... actually ... yes Embarassed but i did not expect there this Smile
to be honest i did not know that string can be used as an index of other string ...
sorry Smile

regards.
View user's profileFind all posts by ppvSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
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.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 08 Mar 2006
Posts: 63
Reply with quote
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.
View user's profileFind all posts by svenaxSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
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...
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 08 Mar 2006
Posts: 63
Reply with quote
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.
View user's profileFind all posts by svenaxSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
yes, it's known and I'd have nothing against '0' to be used as 0 Smile
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 Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website
undefined are defined
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic