Home  >  Article  >  Backend Development  >  What does dot mean in php

What does dot mean in php

下次还敢
下次还敢Original
2024-04-27 11:15:40508browse

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.

What does dot mean in php

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:

  • Used to access array keys: $array['key']
  • As a static method delimiter: Class::method()
  • Use For accessing class constants: 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn