Didn't expect less from your explanation Ammar :) and the values are as you said:
$obj->getNum() = 9; $add = 10; //since $add = $obj->getNum() +1 On 14 May, 11:00, "Ammar Ibrahim" <[EMAIL PROTECTED]> wrote: > You forgot to supply us with the values, but anyhow, it can be derived. See > my answers below > > > > On Wed, May 14, 2008 at 10:35 AM, Codec <[EMAIL PROTECTED]> wrote: > > > Hey Guys, > > > anyone who studied php anatomy,may explain the weired behavior. > > here is the output: > > > # $add = $obj->getNum()+1 # > > # $add = 10 # > > > =========================== > > > Returned Values from a Method: > > > --------------------------- > > > Calculation for : '15 asdasd'.$obj->getNum()+1 > > = 16 > > Calculation for : 'asdasd 15'.$obj->getNum()+1 > > = 1 > > Calculation for : '15'.$obj->getNum()+1 > > = 160 <<=== NOTE1! > > 1- It seems that $obj->getNum() returns (9). In the first example coercion > from string to int happens, and based on PHP rules, the first operand will > be equal to (15) this is because PHP scans the string until the number ends. > If it didn't start with a number, it will be 0. So 15 +1 = 16 > > 2- Concatenation has precedence over addition (actually, same precedence, > but left > associativehttp://www.php.net/manual/en/language.operators.php#language.operator...) > , so the first operand would be 'asdasd 159', which when casted to int would > be 0. So: 0+1 = 1 > > 3- The first operand will be concated, so the results would be '159' > (string). But when the addition happens, coercion happens again, and it > would be 159 + 1 > > This is normal and expected behaviour so far. > > > > > =========================== > > > Variable Calculation: Get Ready for the suprise :) > > > --------------------------- > > > Calculation for : '15 asdasd'.$add+1 > > = 16 > > Calculation for : 'asdasd 15'.$add+1 > > = 1 > > Calculation for : '15'.$add+1 > > = 1511 <<=== Note 2! > > Same as above > 1- The operation wouild '15 asdasd10' + 1. The left operand when casted to > int would be 15, and so on > 2- the left operand when casted to int would be 0 > 3- '15' . 10 is '1510' (string). Then '1510' + 1 is 1511 (int) > > > > > =========================== > > > Propetry Values: > > > --------------------------- > > > Calculation for : '15 asdasd'.$obj->b+1 > > = 16 > > Calculation for : 'asdasd 15'.$obj->b+1 > > = 1 > > Calculation for : '15'.$obj->b+1 > > = 160 > > Again, same rules as above > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Jordan PHP Users Group" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/JoPHP http://Jolug.org/ -~----------~----~----~----~------~----~------~--~---
