-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparent.php
executable file
·58 lines (42 loc) · 1011 Bytes
/
parent.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
56
57
58
<?php
// Example of extending parent's static method
// Add code before, after, or around
class Chef {
public static function make_dinner() {
echo "Cook food.<br />";
}
}
class AmateurChef extends Chef {
public static function make_dinner() {
echo "Read recipe.<br />";
parent::make_dinner();
echo "Clean up mess.<br />";
}
}
echo "Chef:<br />";
Chef::make_dinner();
echo "<br />";
echo "Amateur Chef:<br />";
AmateurChef::make_dinner();
echo "<hr />";
// Example of using parent's static method as a fallback
class Image {
public static $resizing_enabled = true;
public static function geometry() {
echo "800x600";
}
}
class ProfileImage extends Image {
public static function geometry() {
if(self::$resizing_enabled) {
echo "100x100";
} else {
parent::geometry();
}
}
}
echo Image::geometry() . "<br />";
echo ProfileImage::geometry() . "<br />";
echo Image::$resizing_enabled = false;
echo ProfileImage::geometry() . "<br />";
?>