Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<?php
class add
{

private $num1;  
private $num2;

public function set($property,$value)
{
	$this->$property=$value;
}

public function get($property)
{
	return $this->$property;
}

}//end of class math

$obj = new add;
$obj -> set("num1",15);
$obj -> set("num2",3);
echo "First_Number = ".$obj->get("num1")."<br>" ; 
echo "Second_Number = ".$obj->get("num2")."<br>" ;
echo "Addition = " .$obj->get("num1") + $obj->get("num2");
?>


What I have tried:

With the same code.....Multiplication and Division operation are working but having problem with addition and subtraction........?????
Posted
Updated 12-Sep-17 23:31pm
v2
Comments
Richard MacCutchan 13-Sep-17 2:19am    
What problem?

1 solution

php cannot process
PHP
echo "Addition = " .$obj->get("num1") + $obj->get("num2");

as you expect. The following line will show the proper added result
PHP
echo "Addition = " . ( $obj->get("num1") + $obj->get("num2"));



You are not using proper html format, so, your new line will not work on html page
to avoid this, set your content type to plain text. Follow the example below:

header("Content-Type: text/plain");

Set the above line before you declare your class...
 
Share this answer
 
Comments
Member 13406977 15-Sep-17 5:49am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900