pedrobcabral Posted October 2, 2006 Share Posted October 2, 2006 Why does the following $someclass->number+01 returns to me 01+01, when it should return 02? Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/ Share on other sites More sharing options...
.josh Posted October 2, 2006 Share Posted October 2, 2006 sorry, my crystal ball is broken. you'll have to display some code. Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102589 Share on other sites More sharing options...
pedrobcabral Posted October 2, 2006 Author Share Posted October 2, 2006 I have a php class variable that calls number.public $number; (that contains the number 01).While calling a function that adds to that var the number 01, i mean:$myclass->number + 01; this should output 02, once my variable number is set to be 01.Wrongly the result comes to be 01+01, where i wanted to be 02.Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102597 Share on other sites More sharing options...
Hi I Am Timbo Posted October 2, 2006 Share Posted October 2, 2006 Are you sure it is storing the number 01 and not the string 01? PHP doesn't store preceding zeroes. Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102608 Share on other sites More sharing options...
Hi I Am Timbo Posted October 2, 2006 Share Posted October 2, 2006 Are you doing an echo $myclass->number + 01?like was mentioned before, can you show us the code? Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102610 Share on other sites More sharing options...
pedrobcabral Posted October 2, 2006 Author Share Posted October 2, 2006 I guess the problem could be explained like this:[code]<?php$var = 10;echo "Calc: $var+01";?>[/code]The echo goes for "Calc: 10+01" instead of 11.Why? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102613 Share on other sites More sharing options...
Hi I Am Timbo Posted October 2, 2006 Share Posted October 2, 2006 Because PHP doesn't parse the whole string. It treats the string as a string, and inserts the $var as a string. It would have to be like this:[code]<?php$var = 10;echo "Calc: ".($var+01);?>[/code]or this, which changes the value of $var:[code]<?php$var = 10;$var += 01;echo "Calc: $var";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102617 Share on other sites More sharing options...
obsidian Posted October 2, 2006 Share Posted October 2, 2006 right, all your equations need to be done outside of the quotes (unless you're using exec(), but let's not get into that here ;) ):[code]<?php// this outputs "01 + 01"$myClass->number = '01';echo "$myClass->number + 01";// this outputs "2"echo $myClass->number + 1;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.