Php double colon vs arrow

In the sidebar of the php web manual, link text the addChild method uses the :: scope resolution operator, but in the example it uses the Arrow operator. Can anyone tell me why that is?

asked Oct 18, 2010 at 17:01

0

:: is for static elements while -> is for instance elements.

For example:

class Example {
  public static function hello(){
    echo 'hello';
  }
  public function world(){
    echo 'world';
  }
}

// Static method, can be called from the class name
Example::hello();

// Instance method, can only be called from an instance of the class
$obj = new Example();
$obj->world();

More about the static concept

Martin Bean

37k24 gold badges121 silver badges195 bronze badges

answered Oct 18, 2010 at 17:07

wildpeakswildpeaks

7,1282 gold badges29 silver badges35 bronze badges

4

The arrow means the addChild is called as a member of the object (in this case $sxe).

The double colon means that addChild is a member of the SimpleXMLElement class.

answered Oct 18, 2010 at 17:06

This is just notation for the fact that its the method of an object and has nothing to do with actual usage.

In the case of documentation youre not dealing with an instance of an object like $object so the -> operator wouldnt be correct since you want to list the actual class name. So following the usage for a static method where the class name is static you use the scope res. operator ::...

This is generally how php documentation works for classes.

answered Oct 18, 2010 at 17:04

prodigitalsonprodigitalson

59.4k9 gold badges97 silver badges112 bronze badges

In the sidebar of the php web manual, link text the addChild method uses the :: scope resolution operator, but in the example it uses the Arrow operator. Can anyone tell me why that is?

What is the use of :: in PHP?

In PHP, the double colon :: is defined as Scope Resolution Operator. It used when when we want to access constants, properties and methods defined at class level. When referring to these items outside class definition, name of class is used along with scope resolution operator.

What is the difference between -> and => in PHP?

Conclusion. The two operators, => and -> may look similar but are totally different in their usage. => is referred to as double arrow operator. It is an assignment operator used in associative arrays to assign values to the key-value pairs when creating arrays.

What is the arrow in PHP?

Arrow functions are introduced as an update in the PHP version 7.4. Arrow functions are supposed to be a more concise version of anonymous functions. Arrow functions can be seen as shorthand functions that automatically inherit the parent scope's variables.

What is double colon in laravel?

Simply it is token which allow access to static, constant and overridden properties of method of a class.

:: is for static elements while -> is for instance elements.

For example:

class Example {   public static function hello(){     echo 'hello';   }   public function world(){     echo 'world';   } }  // Static method, can be called from the class name Example::hello();  // Instance method, can only be called from an instance of the class $obj = new Example(); $obj->world(); 

More about the static concept

I know that there are two distinct ways to access methods in PHP.

$response->setParameter('foo', 'bar');

And.

sfConfig::set('foo', 'bar');

But what's the difference between them?

Php double colon vs arrow
Jun 14 in PHP by narikkadan
• 16,080 points
45 views

No answer to this question. Be the first to respond.

Your answer

  • All categories
  • Php double colon vs arrow
    Apache Kafka (84)
  • Php double colon vs arrow
    Apache Spark (596)
  • Php double colon vs arrow
    Azure (131)
  • Php double colon vs arrow
    Big Data Hadoop (1,907)
  • Php double colon vs arrow
    Blockchain (1,673)
  • Php double colon vs arrow
    C# (122)
  • Php double colon vs arrow
    C++ (268)
  • Php double colon vs arrow
    Career Counselling (1,060)
  • Php double colon vs arrow
    Cloud Computing (3,356)
  • Php double colon vs arrow
    Cyber Security & Ethical Hacking (145)
  • Php double colon vs arrow
    Data Analytics (1,266)
  • Php double colon vs arrow
    Database (853)
  • Php double colon vs arrow
    Data Science (75)
  • Php double colon vs arrow
    DevOps & Agile (3,500)
  • Php double colon vs arrow
    Digital Marketing (111)
  • Php double colon vs arrow
    Events & Trending Topics (28)
  • Php double colon vs arrow
    IoT (Internet of Things) (387)
  • Php double colon vs arrow
    Java (1,133)
  • Php double colon vs arrow
    Kotlin (3)
  • Php double colon vs arrow
    Linux Administration (384)
  • Php double colon vs arrow
    Machine Learning (337)
  • Php double colon vs arrow
    MicroStrategy (6)
  • Php double colon vs arrow
    PMP (423)
  • Php double colon vs arrow
    Power BI (516)
  • Php double colon vs arrow
    Python (3,141)
  • Php double colon vs arrow
    RPA (650)
  • Php double colon vs arrow
    SalesForce (92)
  • Php double colon vs arrow
    Selenium (1,569)
  • Php double colon vs arrow
    Software Testing (56)
  • Php double colon vs arrow
    Tableau (608)
  • Php double colon vs arrow
    Talend (73)
  • Php double colon vs arrow
    TypeSript (124)
  • Php double colon vs arrow
    Web Development (2,970)
  • Php double colon vs arrow
    Ask us Anything! (66)
  • Php double colon vs arrow
    Others (909)
  • Php double colon vs arrow
    Mobile Development (0)

Join the world's most active Tech Community!

Welcome back to the World's most active Tech Community!

Subscribe to our Newsletter, and get personalized recommendations.

Already have an account? Sign in.

What is the difference between double colon and arrow in PHP?

The arrow means the addChild is called as a member of the object (in this case $sxe). The double colon means that addChild is a member of the SimpleXMLElement class.

What does the :: mean in PHP?

In PHP, the double colon :: is defined as Scope Resolution Operator. It used when when we want to access constants, properties and methods defined at class level. When referring to these items outside class definition, name of class is used along with scope resolution operator.

What is an arrow in PHP?

Arrow functions are introduced as an update in the PHP version 7.4. Arrow functions are supposed to be a more concise version of anonymous functions. Arrow functions can be seen as shorthand functions that automatically inherit the parent scope's variables.

Why does PHP use arrow?

Arrow functions were introduced in PHP 7.4 as a more concise syntax for anonymous functions. Both anonymous functions and arrow functions are implemented using the Closure class.