-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_Static.php
77 lines (56 loc) · 1.22 KB
/
06_Static.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
// 1) Example::
// Static ::
// class Clas
// {
// public $num2 = 100;
// static public $num = 10;
// public function __construct()
// {
// }
// static function fun1()
// {
// //only static variable is access not $this
// self::$num;
// echo "<h4>Tesing.</h4>";
// }
// }
// // No need to create object to access static varriable and method
// // staic value
// echo Clas::$num;
// // echo self::Clas;
// // staic function call
// echo Clas::fun1();
// 2)Example
class Add
{
static public $add = 100;
static function funi()
{
return self::$add++;
}
}
Add::$add;
echo "<br/>";
echo Add::funi();
echo "<hr>";
class Country
{
public $phone;
public static $name = "Nepal";
public static function dispCountryState($x, $contact)
{
echo $phone = $contact;
echo "<h3>" . $x . "<br>";
echo "<h3>" . self::$name;
}
public function tel($c)
{
echo "<h3> " . $this->phone = $c . " </h3>";
}
}
$desh = new Country;
$desh->tel($con = 984563210);
/* $desh->dispCountryState(); */
echo "<h2>" . Country::dispCountryState($sir = "David", $co = 9845803170);
echo "<h1>" . Country::$name;