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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.