AS
PHP
Un esempio di classe
Codice
<?php
class myClass
{
public $flag = 0;//public, protected or private (var is deprecated)
public $name;
public $profile;
function __construct($operator1, $operator2, $operation)
{
$this -> sum = $operator1 + $operator2;
$this -> multiplication = $operator1 * $operator2;
$this -> o = $operation;
}
function myMethod()
{
if($this -> o == "sum")
{
++$this -> flag;
echo $this -> sum . "<br>";
}
else
{
if($this -> o == "multiplication")
{
++$this -> flag;
echo $this -> multiplication . "<br>";
}
}
}
}
$obj1 = new myClass(2, 3, "sum");
$obj1 -> myMethod();
$obj2 = new myClass(2, 3, "multiplication");
$obj2 -> myMethod();
echo $obj2 -> flag;
?>
Output
5
6
1