PHP Static Properties
Static properties वे properties होती हैं जिनका संबंध class से होता है, किसी object से नहीं। Static properties को access करने के लिए object बनाने की आवश्यकता नहीं होती।
- Static property को
staticकीवर्ड की मदद से define किया जाता है। - Static property को access करने के लिए class नाम के बाद scope resolution operator
::का प्रयोग किया जाता है। - Static method की तरह static property भी object context में उपलब्ध नहीं होती, इसलिए
$thisका उपयोग नहीं किया जा सकता।
Static property को दो तरीकों से access किया जा सकता है:
- Inside the Class
- Outside the Class
Inside the Class
क्लास के अंदर static property को access करने के लिए हम self कीवर्ड और
scope resolution operator :: का उपयोग करते हैं, जैसा नीचे उदाहरण में दिखाया गया है:
Outside the Class
क्लास के बाहर static property को access करने के लिए class का नाम और scope resolution
operator :: का उपयोग किया जाता है।
