Financial Calculator

Calculate loans, SIP, PPF, NPS & more!

Financial Calculator

Calculate loans, SIP, PPF, NPS & more!

PHP Static Methods

PHP

PHP Static Methods

Static method वह method होता है जिसे कॉल करने के लिए class का object बनाना ज़रूरी नहीं होता। Static methods को static कीवर्ड की मदद से define किया जाता है और इनका संबंध class से होता है, object से नहीं।

  • Static method घोषित करने के लिए static कीवर्ड का उपयोग किया जाता है।
  • Static method को कॉल करने के लिए हम class के नाम के बाद scope resolution operator :: का उपयोग करते हैं।
  • Static method के अंदर $this का उपयोग नहीं किया जा सकता क्योंकि यह object context में नहीं चलता।

Static method को दो तरीकों से call किया जा सकता है:

  • Inside the Class
  • Outside the Class

Inside the Class

हम self कीवर्ड का उपयोग कर के class के अंदर static method को कॉल कर सकते हैं, जैसे नीचे उदाहरण में दिखाया गया है।

उदाहरण: PHP Static Method inside class
<?php
class Message{
   public static function welcome(){
     echo "Hello, welcome to PHP Static Methods!";
   }
}

class Main{
   public function showMessage(){
     self::display();
   }
}

Message::welcome();

?>
Output
Hello, welcome to PHP Static Methods!

Outside the Class

हम क्लास के बाहर से भी static method को सीधे class नाम और scope resolution operator :: का उपयोग करके कॉल कर सकते हैं, जैसा नीचे उदाहरण में दिखाया गया है।

उदाहरण: PHP Static Method outside class
<?php
class Math{
   public static function add($a, $b){
     return $a + $b;
   }
}

echo Math::add(5, 10);

?>
Output
15
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