-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic-properties.php
More file actions
executable file
·50 lines (41 loc) · 1.48 KB
/
static-properties.php
File metadata and controls
executable file
·50 lines (41 loc) · 1.48 KB
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
<?php
//static properties are class-level variables that are shared among all instances of a class.
//Unlike regular (non-static) properties, static properties belong to the class itself rather than individual objects or instances of the class.
//This means that changes made to a static property will be reflected across all instances of the class.
//blueprint //mold // pattern
class Products {
//properties and method
public static $username="Avinash Tiwari"; //this is properties
static public $email = "avinash@gmail.com";
public $total=5;
function cal_total() // this is method function
{
$this->total = 10*20; //$this represent a current instantiation and $this is called a keyword
return $this->total;
}
function generate_id() // this is method function
{
return rand(0, 99999999);
}
function read()
{
//return $this->total; //$this->total represent current class and where define total variable
$this->cal_total(); // this called same class access an other instantiation using keyword
return $this->total;
}
}
$product = new Products();
$unqnum= Products::generate_id();
echo $unqnum;
echo '<br>';
echo Products::$username;
echo '<br>';
echo Products::$email;
echo '<br>';
echo $product->cal_total();
// echo '<br>';
// echo Products::$total; // if useing keyword you remove static properties
echo '<br>';
$read= $product->read(); // this call defrent type beacouse this function not use defrent type of value and $this represent $product varible
echo $read;
?>