Skip to content

Commit 5a69acd

Browse files
committed
abstract, interfaces, traits, static added
1 parent 99abc2d commit 5a69acd

File tree

7 files changed

+113
-2
lines changed

7 files changed

+113
-2
lines changed

10. Static Method/index.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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();

10. Static Method/index2.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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();

10. Static Method/index3.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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();

7. Abstract Classes/index.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ function __construct($name)
77
$this->name = $name;
88
}
99
abstract function getIntro(): string;
10+
11+
public function getName()
12+
{
13+
return $this->name;
14+
}
1015
}
1116

1217
class Volvo extends Car
@@ -18,8 +23,8 @@ public function getIntro(): string
1823
}
1924

2025
$volvo = new volvo("volvo");
21-
echo $volvo->getIntro();
22-
26+
echo $volvo->getIntro() . "</br>";
27+
echo $volvo->getName();
2328
?>
2429

2530
<!DOCTYPE html>

8. Interfaces/index.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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>

9. Traits/Trait/Message.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
namespace Trait;
3+
4+
?>

9. Traits/index.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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();

0 commit comments

Comments
 (0)