static member function in php example

Solutions on MaxInterview for static member function in php example by the best coders in the world

showing results for - "static member function in php example"
Adèle
05 Aug 2016
1<?php
2/**
3 * we don't need to make object of static variable
4 * when we want to call function but not constructor then we can use constructor
5 */
6class A
7{
8    static public $num = 3;
9    function __construct()
10    {
11
12    }
13    static function fun1() {
14        echo "test<br>";
15        echo self::$num;    //static function inside we can't use this keyword.
16    }
17}
18$obj = new A();
19// echo $obj->num;      -we can't access static data like this 
20// echo $obj->fun1();   -we can't access static data like this 
21echo A::$num;           //we can access static variable like this
22echo A::fun1(); //we can access static function like this
23?>
similar questions
queries leading to this page
static member function in php example