PHP Arrows, Java Equivalent

I am just starting to learn and learn PHP. I have a decent background in Java and I'm trying to make some correlations. One of the completely unfamiliar characters I saw in PHP was the "object access delimiter"? -> as shown in this example:

  <?php class SimpleClass { // property declaration public $var = 'a default value'; // method declaration public function displayVar() { echo $this->var; } } ?> 

From what I explored, it seems that the object access delimiter is equivalent to the dot notation used in Java. For example, 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 guess? Are there any additional ways to use this operator?

+4
source share
2 answers

No, there is no other use ...

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

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

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

+2
source

PHP takes its syntax for objects as much as possible from C ++ as Java. C ++ uses this object for access when specifying object pointers; object variables without a pointer use dot notation. The reason Java didn't take this syntax is because it is not needed because all Java objects, such as pointers to C ++ objects, are created on the heap, so there is only one way to create objects in Java.

+1
source

Source: https://habr.com/ru/post/1394391/


All Articles