Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to access static variables in PHP and How to access static variables in Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 122
    Comment on it

    Hello reader's lets continue with static variable, today we will discuss about "how to access static variables in PHP and Java".


    PHP is usually changing as a Object Oriented language. As being a java coder and PHP coder. Java and PHP possesses completely different run time environment architecture, we will discuss some difference about how to access static variable in PHP and Java. Both equally Java and PHP possesses concept about "class" and "instance of class" now.
    In below example "accessTest" is used as class in code. A "new accessTest()" is used as instance (object) of class in code. However, I recognized an difference of calling static member in class in between PHP and Java. Inside Java, any static variable can be referred by way of a instance of class even though it is not encouraged. Inside PHP, it is not allowed to do so in below test

    Here is the java example.

    /**
     *
     * @Coder Jaydeep Dhoundiyal
     */
    public class accessTest {
    
        public static String dummyVar = "Hello";
    
        public static void main(String[] args) {
            accessTest obj = new accessTest();
            //I could accessibility this static variable via class illustration.
            //although this is not increased.
            System.out.println(obj.dummyVar);
        }
    
    }
    


    And here is Php example

    class accessTest
    {
        static $dummy = 'Hi';
    
        function testStatic()
        {
         print(self::$dummy);
         echo $this->dummy; //error.PHP does not allow.
        }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: