简体   繁体   中英

PHP Arrows, Java Equivalent

I am just starting to research and learn PHP. I have a decent background in Java and I am trying to draw some correlations. One of the completely unfamiliar symbols I saw in PHP was the ?object access seperator? -> as seen in this example:

    <?php
    class SimpleClass
    {
            // property declaration
            public $var = 'a default value';

            // method declaration
            public function displayVar() {
                echo $this->var;
            }
    }
    ?>

From what I have researched, it appears that the object access separator is equivalent to the dot notation used in Java. Such as in the example:

public class SimpleClass
    {
    // property declaration
    public String val = "a default value";

    // method declaration
    public void displayVar() 
    {
        System.out.println(this.val);
    }
}

Is this a safe assumption to make? Are there additional uses of this operator?

Nope, no other use...

http://ca.php.net/manual/en/language.oop5.basic.php

Also note that the :: operator is used to access static members of the class

http://ca.php.net/manual/en/language.oop5.paamayim-nekudotayim.php

PHP borrows its syntax for objects as much from C++ as Java. C++ uses that object accessor when referencing object pointers; non-pointer object variables use the dot notation. The reason Java didn't borrow that syntax is that it is unnecessary because all Java objects, like C++ object pointers, are created on the heap so there is only one way to create objects in Java.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM