Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 8 of 13 · PHP Basics & Syntax
Interview question

What is the difference between GET and POST methods? GET और POST मेथड्स में क्या अंतर है?

Answer

Short Answer

Default parameters allow you to assign a default value to a function parameter. If the caller does not pass an argument for that parameter, the default value is used instead of throwing an error.

Detailed Explanation & Code Example

Default parameters are incredibly useful for making functions flexible and keeping function signatures clean when certain arguments are almost always the same.


// $role has a default value of 'Guest'
function createUser($name, $role = "Guest") {
    echo "Created user: $name, Role: $role\n";
}

// We don't provide a second argument, so 'Guest' is used.
createUser("Alice"); 
// Output: Created user: Alice, Role: Guest

// We provide a second argument, which overrides the default.
createUser("AdminBob", "Administrator"); 
// Output: Created user: AdminBob, Role: Administrator

Common Mistakes

Ordering matters! Optional parameters (those with default values) must always be placed after required parameters in the function definition. Otherwise, PHP won't know which arguments align with which parameters.


// BAD: Will cause a Fatal Error if called with only one argument
function wrongExample($role = "Guest", $name) { }

// GOOD
function correctExample($name, $role = "Guest") { }
पहलूGETPOST
डेटा विज़िबिलिटीURL में जुड़ा, दिखता हैरिक्वेस्ट बॉडी में, छिपा
डेटा लिमिट~2048 कैरेक्टर्स (ब्राउज़र पर निर्भर)व्यावहारिक रूप से कोई लिमिट नहीं
कैशिंगकैश/बुकमार्क हो सकता हैकैश नहीं होता
उपयोगडेटा फेच/सर्च करनाफॉर्म सबमिट, संवेदनशील डेटा
सुरक्षाकम सुरक्षित, URL/history में दिखता हैज़्यादा सुरक्षित (फिर भी HTTPS + validation चाहिए)

इंटरव्यू टिप: बताएं कि असली सुरक्षा HTTPS, इनपुट validation और CSRF protection से आती है, सिर्फ HTTP मेथड से नहीं।

Was this answer clear?