Home > Article > Backend Development > What does dot mean in php
The dot operator in PHP can be used to: access object properties. Call object methods. connection string. Access array keys. As a static method delimiter. Access class constants.
The meaning of dot in PHP
The dot (.) in PHP is an operator used to access The properties of the object and the methods of calling the object.
Accessing Object Properties
When you have an object, you can access its properties using the dot operator. For example:
<code class="php">$object = new stdClass(); $object->property = 'value'; echo $object->property; // 输出:value</code>
Call object method
To call an object method, you can also use the dot operator. The method name is followed by parentheses and the parameter list. For example:
<code class="php">class MyClass { public function myMethod() { // 执行方法 } } $object = new MyClass(); $object->myMethod();</code>
Concatenating strings
In PHP, the dot operator can also be used to concatenate strings. For example:
<code class="php">$str1 = 'Hello'; $str2 = 'World'; $str = $str1 . '.' . $str2; // 输出:Hello.World</code>
Other uses
In addition to the above usage, the dot operator has some other uses in PHP:
$array['key']
Class::method()
Class::CONSTANT
The above is the detailed content of What does dot mean in php. For more information, please follow other related articles on the PHP Chinese website!