Overriding Kya Hai In Php

Hello friends web in hindi me apka swaggat hai ajj me apko php me overidding ke bare me btaunga ye word apne bhut bar sunna hoga .To friends me apko ye simple se example sebtaunga takki apko smjhne me asani ho.
Overriding Kya Hai In Php-
overriding ek esa method hai oops me jisme perental behaviour ko child class me replace kar diya jat hai.simple word me hm keh skte hai ki method ke behaveiour ko change kar dene ko he overidding kaha jata hai
class tv{
public $model='abc';
}
class plaza extends tv{
}
$tv=new tv;
$plaza=new plaza;
echo $tv->model;
jesa ki aap is example me dekh rhe ho ki hmare pass two class hai tv aur plaza
class plaza class tv ki child class hai means ye class tv se extends hue hai
ab jb hm objects bnate hai or unhe echo krwayege to hmare pass model abc ayega
hm chahe $tv class ya $plaza ka object bnaye or bad me echo krwaye to hmare pass result me model abc  he ayega kiunki hmne class tv (perent class)me model ki value abc di hai.

Bt agar hm plaza class ka alag se variable bna de jese example me bnaye hai $model=’xyz’
Bt ab jb echo(call) krwayege to –
Agar hm $plaza ka object bnakar echo krwate hai to result xyz ayega kiunki is $model variable ne pehle wale variable ko replace kar diya isi ko overidding kehte hai.


Bt agar hm $tv class ka object bnakr  echo krwayege to result abc he ayega kiunki $tv  tv class ka object hai ,to ye apni he class ke variable ,properties ko call krega.
  class tv{
public $model='abc';
}
class plaza extends tv{
public $model='xyz';
}
$plaza=new plaza;
echo $plaza->model;
 Example1-ise aapko me ek example se smjata hu man lo apke papa ke pass ek car hai
or aapke papa us car ko use krte hai or aap be use use karte ho
ab bat ati hai ki aap apne liye apne alag se ek car khrid lete ho
to pehle aap apne papa ki car use krte the ab apne apni car leli to ab aap use use krne lge means apki car ne apke papa ki car ke use ko replace kr diya   ise he overidding kehte hai.

Example2-man lo apke perents  bhut angry  type ke person hai bt aap unke childho or aap bhut shant swbhaw ke person ho to apne apne perents ki angry wali property ko replace kar diya ise he overiiding kehte hai.

Example 3-apke pass do class hai ek class A and class B
Class A perent class hai or class B child class hai class  A me apke pass color variable hai jiski value red hai
Ab app chahe class A ke object bnao ya class b ke or fir call kro to apke pass value red he ayegi.
Bt agar aap bad me class B ka alag se color variable bna dete ho or uski value change(green) kr dete ho fir Class B ke Object Bnakar call krate ho to apke pass result green ayega.hua ye ki child class ke variable ne perent class ke variable ko override kar diya.
Note-overidding krne ke liye apko simple sa step karna hota hai ki apko apne parent class me koi function hai aap same usi function ke name ka function child class me bna do or uski value change kr do ab jb aap function call kroge to apke pass result or value vo ayegi jo apne child class me di hai means child class ke function ne perent class ke function ko override kar diya.


Me ummid krta hu ki apko hmare ye post smajh me agyi hogi agar apki koi be proble ho to comment me btaiye or agar apko post achi lgi ho to ise social sites par share karna mt bhuliyega.
Thank you
Team Gajabwap Web in Hindi
Also Read
Previous
Next Post »
Thanks for your comment