TOP 20 PHP PROGRAMMING QUESTIONS
AND CORRECT ANSWERS
WhatA2isA2objectA2orientedA2programming?A2-A2Ans--ect-
orientedA2programmingA2isA2aA2styleA2ofA2codingA2thatA2allowsA2developersA2toA2groupA2si
milarA2tasksA2intoA2classes.A2ThisA2helpsA2keepA2codeA2followingA2theA2tenetA2"don'tA2repe
atA2yourself"A2(DRY)A2andA2easy-to-maintain.
"Object-
orientedA2programmingA2isA2aA2styleA2ofA2codingA2thatA2allowsA2developersA2toA2groupA2si
milarA2tasksA2intoA2classes."
OneA2ofA2theA2majorA2benefitsA2ofA2DRYA2programmingA2isA2that,A2ifA2aA2pieceA2ofA2inform
ationA2changesA2inA2yourA2program,A2usuallyA2onlyA2oneA2changeA2isA2requiredA2toA2updat
eA2theA2code.A2OneA2ofA2theA2biggestA2nightmaresA2forA2developersA2isA2maintainingA2cod
eA2whereA2dataA2isA2declaredA2overA2andA2overA2again,A2meaningA2anyA2changesA2toA2the
A2programA2becomeA2anA2infinitelyA2moreA2frustratingA2gameA2ofA2Where'sA2Waldo?
A2asA2theyA2huntA2forA2duplicatedA2dataA2andA2functionality.
InA2PHPA2whatA2isA2theA2differenceA2betweenA2aA2ClassA2andA2anA2Interface?A2-A2Ans--
cesA2doA2notA2containA2businessA2logic,A2onlyA2methodA2signaturesA2thatA2defineA2aA2tem
plateA2thatA2anyA2classesA2implementingA2theA2interfaceA2mustA2contain.A2LetsA2takeA2anA
2autoA2mobileA2forA2example.A2IfA2weA2wereA2toA2createA2andA2interfaceA2forA2aA2carA2weA2
wouldA2wantA2toA2defineA2aA2fewA2methodsA2likeA2drive,A2stop,A2turnA2leftA2,A2turnA2right.A2T
hisA2meanA2thatA2anyA2vehicleA2thatA2isA2aA2carA2(akaA2implementsA2theA2interfaceA2car)A2
mustA2haveA2methodsA2forA2theseA2things,A2IfA2theyA2doA2notA2PHPA2willA2throwA2anA2error
.A2SoA2ifA2yourA2carA2isA2anA2BMWA2,A2HondaA2orA2FordA2itA2mustA2beA2ableA2toA2stop.A2Ho
wA2itA2stopsA2isA2upA2toA2eachA2carA2(orA2PHPA2class)A2butA2itA2mustA2beA2ableA2toA2stop.A2
TechnicallyA2weA2canA2decideA2notA2toA2useA2anA2interfaceA2forA2cars,A2butA2thenA2someA2t
ypesA2ofA2carsA2areA2notA2forcedA2toA2haveA2aA2"stop"A2method.
WhatA2isA2MVC?A2-A2Ans--ModelA2-
A2UsuallyA2containsA2dataA2accessA2codeA2andA2allA2ofA2youA2businessA2logicA2code.A2
ViewA2-A2ContainsA2markup/designA2code,A2generallyA2html,xml,A2json.A2
ControllerA2-
A2UsuallyA2containsA2veryA2littleA2code,A2justA2whateverA2isA2neededA2toA2callA2theA2ModelA
2codeA2andA2renderA2theA2ViewA2code.
ExplainA2howA2aA2PHPA2sessionA2works?A2-A2Ans--
AA2PHPA2sessionA2cookieA2isA2setA2inA2theA2clientsA2browser,A2onA2everyA2requestA2theA2cl
ientA2sendsA2thatA2cookieA2toA2theA2server.A2PHPA2thenA2usesA2thatA2cookieA2toA2selectA2t
heA2correspondingA2sessionA2information.A2ByA2defaultA2PHPA2session_start()A2willA2store
A2sessionA2dataA2inA2files,A2youA2canA2alsoA2storeA2sessionsA2inA2aA2database.
AND CORRECT ANSWERS
WhatA2isA2objectA2orientedA2programming?A2-A2Ans--ect-
orientedA2programmingA2isA2aA2styleA2ofA2codingA2thatA2allowsA2developersA2toA2groupA2si
milarA2tasksA2intoA2classes.A2ThisA2helpsA2keepA2codeA2followingA2theA2tenetA2"don'tA2repe
atA2yourself"A2(DRY)A2andA2easy-to-maintain.
"Object-
orientedA2programmingA2isA2aA2styleA2ofA2codingA2thatA2allowsA2developersA2toA2groupA2si
milarA2tasksA2intoA2classes."
OneA2ofA2theA2majorA2benefitsA2ofA2DRYA2programmingA2isA2that,A2ifA2aA2pieceA2ofA2inform
ationA2changesA2inA2yourA2program,A2usuallyA2onlyA2oneA2changeA2isA2requiredA2toA2updat
eA2theA2code.A2OneA2ofA2theA2biggestA2nightmaresA2forA2developersA2isA2maintainingA2cod
eA2whereA2dataA2isA2declaredA2overA2andA2overA2again,A2meaningA2anyA2changesA2toA2the
A2programA2becomeA2anA2infinitelyA2moreA2frustratingA2gameA2ofA2Where'sA2Waldo?
A2asA2theyA2huntA2forA2duplicatedA2dataA2andA2functionality.
InA2PHPA2whatA2isA2theA2differenceA2betweenA2aA2ClassA2andA2anA2Interface?A2-A2Ans--
cesA2doA2notA2containA2businessA2logic,A2onlyA2methodA2signaturesA2thatA2defineA2aA2tem
plateA2thatA2anyA2classesA2implementingA2theA2interfaceA2mustA2contain.A2LetsA2takeA2anA
2autoA2mobileA2forA2example.A2IfA2weA2wereA2toA2createA2andA2interfaceA2forA2aA2carA2weA2
wouldA2wantA2toA2defineA2aA2fewA2methodsA2likeA2drive,A2stop,A2turnA2leftA2,A2turnA2right.A2T
hisA2meanA2thatA2anyA2vehicleA2thatA2isA2aA2carA2(akaA2implementsA2theA2interfaceA2car)A2
mustA2haveA2methodsA2forA2theseA2things,A2IfA2theyA2doA2notA2PHPA2willA2throwA2anA2error
.A2SoA2ifA2yourA2carA2isA2anA2BMWA2,A2HondaA2orA2FordA2itA2mustA2beA2ableA2toA2stop.A2Ho
wA2itA2stopsA2isA2upA2toA2eachA2carA2(orA2PHPA2class)A2butA2itA2mustA2beA2ableA2toA2stop.A2
TechnicallyA2weA2canA2decideA2notA2toA2useA2anA2interfaceA2forA2cars,A2butA2thenA2someA2t
ypesA2ofA2carsA2areA2notA2forcedA2toA2haveA2aA2"stop"A2method.
WhatA2isA2MVC?A2-A2Ans--ModelA2-
A2UsuallyA2containsA2dataA2accessA2codeA2andA2allA2ofA2youA2businessA2logicA2code.A2
ViewA2-A2ContainsA2markup/designA2code,A2generallyA2html,xml,A2json.A2
ControllerA2-
A2UsuallyA2containsA2veryA2littleA2code,A2justA2whateverA2isA2neededA2toA2callA2theA2ModelA
2codeA2andA2renderA2theA2ViewA2code.
ExplainA2howA2aA2PHPA2sessionA2works?A2-A2Ans--
AA2PHPA2sessionA2cookieA2isA2setA2inA2theA2clientsA2browser,A2onA2everyA2requestA2theA2cl
ientA2sendsA2thatA2cookieA2toA2theA2server.A2PHPA2thenA2usesA2thatA2cookieA2toA2selectA2t
heA2correspondingA2sessionA2information.A2ByA2defaultA2PHPA2session_start()A2willA2store
A2sessionA2dataA2inA2files,A2youA2canA2alsoA2storeA2sessionsA2inA2aA2database.