PHP Interview Questions and Answers Paper three
1. Differentiate between variables and constants in PHP
Variables | Constants |
---|---|
The value of a variable can be changed during the execution. | The constant value can’t be changed during script execution. |
Variables require compulsory usage of the $ sign at the start. | No dollar sign ($) is required before using a constant. |
It is possible to define a variable by simple assignment. | Constants can’t be defined by simple assignments. They are defined using the define() function. |
The default scope is the current access scope. | Constants can be accessed throughout without any scoping rules. |
difference between $ and $$.
$message | $$message |
---|---|
$message is a regular variable. | $$message is a reference variable. |
It has a fixed name and stores a fixed value. | It stores data about the variable. |
Data stored in $message is fixed. | The value of the $$message can change dynamically as the value of the variable changes. |
What is the difference between “echo” and “print” in PHP?
echo | |
---|---|
echo can output one or more strings. | print can only output one string and it always returns 1. |
echo is faster than print because it does not return any value. | print is slower compared to echo. |
If you want to pass more than one parameter to echo, a parenthesis should be used. | Use of parenthesis is not required with the argument list. |
What is the difference between Session and Cookies ?
Cookie | Session |
---|---|
Cookies are client-side files on a local computer that hold user information. | Sessions are server-side files that contain user data. |
Cookies end on the lifetime set by the user. | When the user quits the browser or logs out of the programmed, the session is over. |
It can only store a certain amount of info. | It can hold an indefinite quantity of data. |
The browser’s cookies have a maximum capacity of 4 KB. | We can keep as much data as we like within a session, however there is a maximum memory restriction of 128 MB that a script may consume at one time. |
Because cookies are kept on the local computer, we don’t need to run a function to start them. | To begin the session, we must use the session start() method. |
Cookies are not secured. | Session are more secured compare than cookies. |
Cookies stored data in text file. | Session save data in encrypted form. |
Cookies stored on a limited data. | Session stored a unlimited data. |
In PHP, to get the data from Cookies , $_COOKIES the global variable is used | In PHP , to set the data from Session, $_SESSION the global variable is used |
We can set an expiration date to delete the cookie’s data. It will automatically delete the data at that specific time. | In PHP, to destroy or remove the data stored within a session, we can use the session_destroy() function, and to unset a specific variable, we can use the unset() function. |
What is the difference between GET and POST?
S.No. | GET Request | POST Request |
---|---|---|
1. | GET retrieves a representation of the specified resource. | POST is for writing data, to be processed to the identified resource. |
2. | It typically has relevant information in the URL of the request. | It typically has relevant information in the body of the request. |
3. | It is limited by the maximum length of the URL supported by the browser and web server. | It does not have such limits. |
4. | It is the default HTTP method. | In this, we need to specify the method as POST to send a request with the POST method. |
5. | You can bookmark GET requests. | You cannot bookmark POST requests. |
6. | It is less secure because data sent is part of the URL | It is a little safer because the parameters are not stored in browser history or in web server logs. |
7. | It is cacheable. | It is not cacheable. |
8. | For eg. GET the page showing a particular question. | For eg. Send a POST request by clicking the “Add to cart” button. |
Related post
EknowledgePoint
Increase Your Knowledge with usEknowledgePoint is an innovative online learning platform that aims to democratize education by providing a vast array of courses and educational content to learners of all ages and backgrounds. It offers a diverse range of subjects, from academic topics to practical skills, making it a one-stop destination for anyone looking to expand their knowledge base.
5 comments
Knowledge is the fuel that powers our journey through life. It's platforms like EknowledgePoint that transform information into enlightenment, curiosity into competence, and dreams into reality. Embrace the opportunity to learn, and you'll find that the doors of possibility swing wide open. 🚀💡 #EknowledgePoint.
Thank you for your kind words! At EknowledgePoint, we are dedicated to empowering individuals on their learning journey. Your enthusiasm for knowledge and personal growth inspires us to keep providing the best educational resources and experiences. Let's continue to explore and learn together!.
Thanks For Your Support.
"I'm constantly amazed by the quality of instructors on EknowledgePoint. Learning from experts in their fields is both enlightening and empowering. 🌟👨🏫 #EknowledgePoint.
EknowledgePoint isn't just a platform; it's a community of learners. The support and camaraderie here are truly inspiring. 🤝🌍 #EknowledgePoint.