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?
• 16,080 points • 45 views
No answer to this question. Be the first to respond.
Your answer
Related Questions In PHP
- All categories
- Apache Kafka (84)
- Apache Spark (596)
-
Azure (131)
- Big Data Hadoop (1,907)
- Blockchain (1,673)
-
C# (122)
- C++ (268)
- Career Counselling (1,060)
-
Cloud Computing (3,356)
- Cyber Security & Ethical Hacking (145)
- Data Analytics (1,266)
- Database (853)
- Data Science (75)
- DevOps & Agile (3,500)
-
Digital Marketing (111)
- Events & Trending Topics (28)
- IoT (Internet of Things) (387)
-
Java (1,133)
- Kotlin (3)
- Linux Administration (384)
-
Machine Learning (337)
- MicroStrategy (6)
- PMP (423)
-
Power BI (516)
- Python (3,141)
- RPA (650)
-
SalesForce (92)
- Selenium (1,569)
- Software Testing (56)
-
Tableau (608)
- Talend (73)
- TypeSript (124)
-
Web Development (2,970)
- Ask us Anything! (66)
- Others (909)
-
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.