Jump to content

oop problem - url


pedrobcabral

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102597
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102617
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/22779-oop-problem-url/#findComment-102622
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.