-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties-accessors.php
More file actions
executable file
·50 lines (37 loc) · 1.25 KB
/
properties-accessors.php
File metadata and controls
executable file
·50 lines (37 loc) · 1.25 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
//public //private //protected //static
//public access the inside the class and outside the class any where access the public function
class Products {
//properties and method
public $username="Avinash Tiwari"; //public id Access modifiers
public static $email = "avinash@gmail.com";//private id Access modifiers
public static $total=5;
public function cal_total() // this is method function
{
self::$total = 10*20; //Self meaning class itself ya self is this same class name & $total is static varible if you change access modifier so get some error
}
public function generate_id() // this is method function
{
return rand(0, 99999999);
}
public function read()
{
$this->cal_total(); // this called same class access an other instantiation using keyword
return self::$total;
}
}
$product = new Products();
$unqnum= Products::generate_id();
echo $unqnum;
echo '<br>';
echo $product->cal_total();
// echo '<br>';
// echo Products::$username;
echo '<br>';
echo Products::$email;
// 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;
?>