Php Access Specifiers Kya Hai

Php Access Specifiers Kya Hai
Ye wo rights hote hai oops me jo decide krte hai ki kon se class ke object kon se class ke
member,properties etc ko access kar skte hai.in a simple words ye kisi be property ke visibility ke bare me decide karte hai.

Access specifiers 3 trah ke hote hai
Private
Protected
Public

Private-
private access specifies wo hote hai jo with in a class me he access ho skte hai inhe outsize se access ne kiya ja skta
Example-jesa apka mobile phone hai mobile phone personal hota hai ise hmare ilawa koi be use ne kr skta hai  ise aap private man skte ho
Protected-
Protected vo hote hai jinhe class ke member aur us class se jo new class extend hoti hai us class ke member he access kr skte hai
Example-man lijiye apke pass ek car hai to us car ka use aap be kr skte ho or apki family ke members be apke bhai bhan children etc
Public-
Public accss specifiers  vo hote hai jinhe koi be access kr skta hai means
Inhe inside,outside ya knhi se be koi be member access kr skta hai
Example-
App isme govt bus ka example le skte ho jinka use koi be kr skta hai andar se bahr se knhi se be

Class tv{
Public $model=’abc’;
Private $color=’red’;
Protected $volume=5;
}
Class plaza extends tv{
Public $size=20;
}
Class sony {
Public $cost=10;
}
$tv=new tv;
Echo $tv->model;

Jesa ki aap example me dekh rhe ho yanha $model public hai
Iska mtlb ye hai ki hm ise knhi se be access kr skte hai means class tv ke andar se be or plaza tv ke andar se be
Access or call kese krte hai-
Jesa ki aap example me dekh rhe ho hmne tv and plaza class bnane ke bad object bnaya hai $tv or uske bad echo ke dwara model ko call kiya hai.ise jb aap exexute kroge to apke pass model ki value abc a jayegi program run hone par kiunki ye public hai
Ab hm plaza tv ka object bnakar call krege $color ko
Plaza tv ka object kese bnaye
$plaza=new plaza;
Echo $plaza->color;
Bt ab hmare pass error ayega jo niche btaya hai mene.

Notice: Undefined property: plaza::$color in C:\wamp\www\static\mywapy.php on line 17
 Kiunki $color tv class ka member hai
Or ye private hai mene apko btaya tha ki private access specifier ko inside  class se he access kiya jata hai outside se nhi
Yanha hmne $plaza jo object bnaya hai wo plaza  class ka hai isi karan hm $color properties ko access ne kar pa rhe hai
Bt agar hm $model ko access kr skte hai kiunki wo public hai.....$model ko hm $plaza ke objects and $tv ke objects dono se access kr skte hai kiunki $model public hai.
Bt hm $color ko sirf $tv ka object bnaker he access kr skte hai kiunki ye private hai .ise hm $plaza ka object bnakar access ne kar skte.or na he $sony ka object bnakar.
Ab bat ati hai $volume ki jo ki protected hai to ise hm $tv,$plaza ka object bnakar access kr skte hai bt hm ise
$sony k object bnakr access ne kr skte .because mene apko upar btaya tha ki protect properties ko sirf us class ke memer or usse extend hue class(means uski child class)ke member he us property ko access kr skte hai.
To dosto mujhe ummid hai apko access specifiers ki post achi lgi hogi gar apka koi be swal ho to plz comment kijiye
Thank you
Team Gajabwap Web In Hindi
 Also read-
Previous
Next Post »
Thanks for your comment