-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor-destructor.php
More file actions
47 lines (37 loc) · 1016 Bytes
/
constructor-destructor.php
File metadata and controls
47 lines (37 loc) · 1016 Bytes
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
<?php
class Person
{
public $firstName;
public $lastName;
public function __construct($firstName, $lastName)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
}
}
class Triangle
{
public $sideOne;
public $sideTwo;
public $sideThree;
public function __construct($sideOne, $sideTwo, $sideThree);
{
$this->sideOne = $sideOne;
$this->sideTwo = $sideTwo;
$this->sideThree = $sideThree;
}
public function __destruct()
{
echo "Done!".PHP_EOL;
}
public function perimeter(){
return $this->sideOne + $this->sideTwo + $this->sideThree;
}
}
$triangle = new Triangle(2, 3, 4);
echo $triangle->perimeter().PHP_EOL;
$kristen = new Person('Kristen', 'Cates');
echo $kristen->firstName.PHP_EOL;
// $ashley = new Person();
// $ted = new Person();
?>