Financial Calculator

Calculate loans, SIP, PPF, NPS & more!

Financial Calculator

Calculate loans, SIP, PPF, NPS & more!

PHP Static Properties

PHP

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 :: का उपयोग करते हैं, जैसा नीचे उदाहरण में दिखाया गया है:

उदाहरण: PHP Static Property inside class
<?php
class Counter{
   public static $count = 0;

   public function increase(){
     self::$count++;
   }
}

$obj1 = new Counter();
$obj2 = new Counter();

$obj1->increase();
$obj2->increase();

echo Counter::$count;

?>
Output
2

Outside the Class

क्लास के बाहर static property को access करने के लिए class का नाम और scope resolution operator :: का उपयोग किया जाता है।

उदाहरण: PHP Static Property outside class
<?php
class Test{
   public static $name = "Hindicode";
}

echo Test::$name;

?>
Output
Hindicode
Article By: Brajlal Prasad
Created on: 03 Nov 2025  8  Views
 Print Article
Report Error

If you want to report an error, or any suggestion please send us an email to [email protected]

Financial Calculator

Financial Calculator

Take control of your finances with our powerful Financial Calculator app—calculate loans, SIP, PPF, NPS and more all in one place!

Play Store