" symbol after new comes out, with codes such as "$a ->index();"."/> " symbol after new comes out, with codes such as "$a ->index();".">

Home  >  Article  >  Backend Development  >  php method of calling object

php method of calling object

藏色散人
藏色散人Original
2019-11-01 09:24:364999browse

php method of calling object

php Call the method of the object

php Call and introduce the object

Directly go to the instance :

Definition:

<?php
namespace app\php;
class a
{
    static $q = 888;
    public function index()
    {
        echo "1111";
    }
    
    static function debug()
    {
        echo "<br/>";
        echo 555;
    }
}

Usage:

<?php
namespace app\php;
include "./a.php";
class b
{
    public function b()
    {
        echo 111;
    }
}
 $b = new b();
$b ->b();
$a = new a();
$a ->index();
echo $a::$q;
$a::debug();

In PHP, for object properties (non-static) and methods (non-static), use "new" after coming out -> "This is consistent with access. Unlike other languages, use "." directly after new to access.

To access static data, use the "::" symbol to access it.

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of php method of calling object. 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