php method of calling object

藏色散人
Release: 2023-02-28 09:00:01
Original
4989 people have browsed it

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;
    }
}
Copy after login

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();
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template