- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymorphism.php
More file actions
Latest commit
26 lines (21 loc) Β· 594 Bytes
/
Copy pathpolymorphism.php
File metadata and controls
26 lines (21 loc) Β· 594 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
<?php
echo'<h1>Polymorphsim</h1>';
// Practice
abstractclass User {
protected$scores = 0;
protected$numberOfArticles = 0;
publicfunctionsetNumberOfArticles($int) {
$this -> numberOfArticles = (int)$int;
// (int) converts a value to an integer.
}
publicfunctiongetNumberOfArticles() {
return$this -> numberOfArticles;
}
// The abstract method.
abstractpublicfunctioncalcScores();
}
class Author extends User {
publicfunctioncalcScores() {
return$this -> scores = $this -> numberOfArticles * 10 + 20;
}
}