Arithmetic Operators

Remember basic arithmetic from school? These work just like those.

Table 14-2. Arithmetic Operators

ExampleNameResult
-$aNegationOpposite of $a.
$a + $bAdditionSum of $a and $b.
$a - $bSubtractionDifference of $a and $b.
$a * $bMultiplicationProduct of $a and $b.
$a / $bDivisionQuotient of $a and $b.
$a % $bModulusRemainder of $a divided by $b.

The division operator ("/") returns a float value anytime, even if the two operands are integers (or strings that get converted to integers).

See also the manual page on Math functions.

nbsp;print "MyClass::printHello() " . $this->private;
      print
"MyClass::printHello() " . $this->protected;
      print
"MyClass::printHello() " . $this->protected2;
   }
}

class
MyClass2 extends MyClass {
   
protected $protected = "MyClass2::protected!\n";

   function
printHello() {

      
MyClass::printHello();    

      print
"MyClass2::printHello() " . $this->public;
      print
"MyClass2::printHello() " . $this->protected;
      print
"MyClass2::printHello() " . $this->protected2;

      
/* Will result in a Fatal Error: */
      //print "MyClass2::printHello() " . $this->private; /* Fatal Error */

   
}
}

$obj = new MyClass();

print
"Main:: " . $obj->public;
//print $obj->private; /* Fatal Error */
//print $obj->protected;  /* Fatal Error */
//print $obj->protected2;  /* Fatal Error */

$obj->printHello(); /* Should print */

$obj2 = new MyClass2();
print
"Main:: " . $obj2->private; /* Undefined */

//print $obj2->protected;   /* Fatal Error */
//print $obj2->protected2;  /* Fatal Error */

$obj2->printHello();
?>