File tree 7 files changed +113
-2
lines changed
7 files changed +113
-2
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class greeting
4
+ {
5
+ public static function message ()
6
+ {
7
+ return "This is a message " ;
8
+ }
9
+ }
10
+
11
+
12
+ echo greeting::message ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+ class greeting
3
+ {
4
+ public static function welcome ()
5
+ {
6
+ echo "This is welcome message " ;
7
+ }
8
+ public function __construct ()
9
+ {
10
+ self ::welcome ();
11
+ }
12
+ }
13
+
14
+ new greeting ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+ class Domain
3
+ {
4
+ protected static function welcome ()
5
+ {
6
+ echo "this is welcome message " ;
7
+ }
8
+ }
9
+
10
+ class DomainW3 extends Domain
11
+ {
12
+ public function __construct ()
13
+ {
14
+ parent ::welcome ();
15
+ }
16
+ }
17
+
18
+ new DomainW3 ();
Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ function __construct($name)
7
7
$ this ->name = $ name ;
8
8
}
9
9
abstract function getIntro (): string ;
10
+
11
+ public function getName ()
12
+ {
13
+ return $ this ->name ;
14
+ }
10
15
}
11
16
12
17
class Volvo extends Car
@@ -18,8 +23,8 @@ public function getIntro(): string
18
23
}
19
24
20
25
$ volvo = new volvo ("volvo " );
21
- echo $ volvo ->getIntro ();
22
-
26
+ echo $ volvo ->getIntro () . " </br> " ;
27
+ echo $ volvo -> getName ();
23
28
?>
24
29
25
30
<!DOCTYPE html>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ interface Animal
3
+ {
4
+ public function makeSound ();
5
+ }
6
+
7
+ interface Mammal extends Animal
8
+ {
9
+ public function takeMilks ();
10
+ }
11
+
12
+ class Monkey implements Mammal
13
+ {
14
+ public function makeSound ()
15
+ {
16
+ return "make Sound " ;
17
+ }
18
+ public function takeMilks ()
19
+ {
20
+ return "Take Milks " ;
21
+ }
22
+ }
23
+
24
+ $ monkey = new Monkey ();
25
+
26
+ echo $ monkey ->makeSound () . "</br> " . $ monkey ->takeMilks () . "</br> " ;
27
+
28
+ ?>
29
+ <!DOCTYPE html>
30
+ <html lang="en">
31
+
32
+ <head>
33
+ <meta charset="UTF-8">
34
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
35
+ <title>Interfaces</title>
36
+ </head>
37
+
38
+ <body>
39
+
40
+ </body>
41
+
42
+ </html>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Trait ;
3
+
4
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ trait Message
3
+ {
4
+ public function getMessage ()
5
+ {
6
+ return "This is a test message " ;
7
+ }
8
+ }
9
+ class MyClass
10
+ {
11
+ use Message;
12
+ }
13
+
14
+ $ class = new MyClass ();
15
+
16
+ echo $ class ->getMessage ();
You can’t perform that action at this time.
0 commit comments