-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandc.php
55 lines (41 loc) · 978 Bytes
/
sandc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
class BankAccount {
//This will allow the tax rate to be changed outside
//of the class.
public static $tax = .09;
//A better way (constants are always capitalized):
const TAX = .09;
}
echo 'BankAccount ', BankAccount::TAX, PHP_EOL;
class Person {
public $age = 1;
public function haveBirthday()
{
$this->age += 1;
}
public function age()
{
return $this->age;
}
}
$joe = new Person;
$joe->haveBirthday();
$joe->haveBirthday();
echo ' joe ', $joe->age(), PHP_EOL;
$jane = new Person;
$jane->haveBirthday();
echo ' jane ', $jane->age(), PHP_EOL;
// '::' is the Scope Resolution Operator
//echo Person::$age;
class Math {
//When you think 'static', think 'share;
public static function add()
{
return array_sum(func_get_args());
}
}
//$math = new Math;
//
//var_dump($math->add(1, 2, 3, 4, 5, 6, 7));
//This code is replaced with
echo ' math ', Math::add(1, 2, 3), PHP_EOL;