Hướng nội trong php giải thích với ví dụ là gì?

Các chức năng hướng nội hiếm khi được sử dụng khi xây dựng biểu định kiểu. Tuy nhiên, chúng có giá trị nếu có điều gì đó không hoạt động bình thường - để tìm hiểu điều gì đang xảy ra. như chức năng gỡ lỗi

Bảng sau liệt kê tất cả các chức năng hướng nội trong Sass

Mô tả chức năng và gọi ví dụ (hàm, đối số. ) Gọi một hàm có đối số và trả về kết quả. content-exists() Kiểm tra xem mixin hiện tại có được thông qua khối @content hay không. feature-exists(feature)Kiểm tra xem tính năng có được triển khai Sass hiện tại hỗ trợ hay không

Thí dụ
tính năng tồn tại ("lỗi");
Kết quả. ĐÚNG VẬY

chức năng tồn tại (tên chức năng) Kiểm tra xem chức năng được chỉ định có tồn tại không

Thí dụ
chức năng tồn tại ("vô nghĩa")
Kết quả. sai

hàm get (tên hàm, css. false) Trả về hàm đã chỉ định. Nếu css là true, thay vào đó, nó sẽ trả về một hàm CSS đơn giản. biến toàn cầu tồn tại (tên biến) Kiểm tra xem biến toàn cục đã chỉ định có tồn tại không

Thí dụ
biến-tồn tại(a)
Kết quả. ĐÚNG VẬY

kiểm tra (giá trị) Trả về một chuỗi đại diện của giá trị. mixin-exists(mixinname)Kiểm tra xem mixin đã chỉ định có tồn tại không

Thí dụ
mixin-exists("văn bản quan trọng")
Kết quả. ĐÚNG VẬY

type-of(value)Trả về loại giá trị. Có thể là số, chuỗi, màu, danh sách, bản đồ, bool, null, hàm, arglist

Thí dụ
loại (15px)
Kết quả. số
loại (#ff0000)
Kết quả. màu

unit(number)Trả về đơn vị được liên kết với một số

Thí dụ
đơn vị (15px)
Kết quả. px

unitless(number) Kiểm tra xem số được chỉ định có đơn vị liên kết với nó không

Thí dụ
đơn vị (15px)
Kết quả. sai
đơn vị(15)
Kết quả. ĐÚNG VẬY

biến tồn tại (tên biến) Kiểm tra xem biến đã chỉ định có tồn tại trong phạm vi hiện tại không

Thí dụ
biến-tồn tại(b)
Kết quả. ĐÚNG VẬY

Nội quan là một tính năng phổ biến trong bất kỳ ngôn ngữ lập trình nào cho phép lập trình viên thao tác với các lớp đối tượng. Bạn sẽ thấy việc xem xét nội tâm đặc biệt hữu ích khi bạn không biết mình cần thực hiện lớp hoặc phương thức nào tại thời điểm thiết kế

Introspection trong PHP cung cấp khả năng hữu ích để kiểm tra các lớp, giao diện, thuộc tính và phương thức. PHP cung cấp một số lượng lớn các hàm mà bạn có thể sử dụng để hoàn thành nhiệm vụ. Để giúp bạn hiểu được nội quan, tôi sẽ cung cấp tổng quan ngắn gọn về một số lớp, phương thức và hàm của PHP bằng cách sử dụng các ví dụ trong PHP để làm nổi bật cách chúng được sử dụng

Trong bài viết này, bạn sẽ thấy một số ví dụ về cách sử dụng một số chức năng nội quan hữu ích nhất của PHP và một phần dành riêng cho API cung cấp chức năng tương tự như nội quan, API Reflection

Hàm nội quan PHP

Trong ví dụ đầu tiên, tôi sẽ trình bày một số hàm nội quan của PHP. Bạn có thể sử dụng các hàm này để trích xuất thông tin cơ bản về các lớp chẳng hạn như tên của chúng, tên của lớp cha của chúng, v.v.

  • class_exists() – kiểm tra xem một lớp đã được xác định chưa
  • get_class() – trả về tên lớp của một đối tượng
  • get_parent_class() – trả về tên lớp của lớp cha của một đối tượng
  • is_subclass_of() – kiểm tra xem một đối tượng có một lớp cha nhất định hay không

Đây là mã PHP ví dụ chứa định nghĩa cho các lớp

The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
0 và
The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
1 và thông tin đầu ra được trích xuất bởi các hàm được liệt kê ở trên

<?php
class Introspection
{
    public function description() {
        echo "I am a super class for the Child class.n";
    }
}

class Child extends Introspection
{
    public function description() {
        echo "I'm " . get_class($this) , " class.n";
        echo "I'm " . get_parent_class($this) , "'s child.n";
    }
}

if (class_exists("Introspection")) {
    $introspection = new Introspection();
    echo "The class name is: " . get_class($introspection) . "n"; 
    $introspection->description();
}

if (class_exists("Child")) {
    $child = new Child();
    $child->description();

    if (is_subclass_of($child, "Introspection")) {
        echo "Yes, " . get_class($child) . " is a subclass of Introspection.n";
    }
    else {
        echo "No, " . get_class($child) . " is not a subclass of Introspection.n";
    }
}

Đầu ra của đoạn mã trên phải như sau

The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.

Bạn có thể xác định xem lớp đã cho đã được xác định hay chưa bằng cách sử dụng phương thức class_exists(), phương thức này nhận một đối số chuỗi đại diện cho tên của lớp mong muốn để kiểm tra và một giá trị Boolean tùy chọn có gọi bộ tải tự động trong quy trình hay không

Các phương thức get_class()get_parent_class() lần lượt trả về tên lớp của một đối tượng hoặc tên lớp cha của nó. Cả hai đều lấy làm đối số một thể hiện đối tượng

Các phương thức is_subclass_of() lấy một thể hiện đối tượng làm đối số đầu tiên của nó và một chuỗi, đại diện cho tên lớp cha và trả về xem đối tượng có thuộc về một lớp là lớp con của lớp được đưa ra làm đối số hay không

Đây là ví dụ thứ hai chứa định nghĩa cho giao diện

The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
6 và lớp
The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
7 và thông tin đầu ra được trích xuất bởi các chức năng được liệt kê ở trên. Như với ví dụ đầu tiên, tôi sẽ liệt kê các chức năng trước và sau đó hiển thị cho bạn một số mã

  • The class name is: Introspection
    I am a super class for the Child class.
    I'm Child class.
    I'm Introspection's child.
    Yes, Child is a subclass of Introspection.
    8 – trả về danh sách tất cả các lớp đã khai báo
  • The class name is: Introspection
    I am a super class for the Child class.
    I'm Child class.
    I'm Introspection's child.
    Yes, Child is a subclass of Introspection.
    9 – trả về tên của các phương thức của lớp
  • <?php
    interface ICurrencyConverter
    {
        public function convert($currency, $amount);
    }
    
    class GBPCurrencyConverter implements ICurrencyConverter
    {
        public $name = "GBPCurrencyConverter";
        public $rates = array("USD" => 0.622846,
                              "AUD" => 0.643478);
        protected $var1;
        private $var2;
    
        function __construct() {}
    
        function convert($currency, $amount) {
            return $rates[$currency] * $amount;
        }
    }
    
    if (interface_exists("ICurrencyConverter")) {
        echo "ICurrencyConverter interface exists.n";
    }
    
    $classes = get_declared_classes();
    echo "The following classes are available:n";
    print_r($classes);
    
    if (in_array("GBPCurrencyConverter", $classes)) {
        print "GBPCurrencyConverter is declared.n";
     
        $gbpConverter = new GBPCurrencyConverter();
    
        $methods = get_class_methods($gbpConverter);
        echo "The following methods are available:n";
        print_r($methods);
    
        $vars = get_class_vars("GBPCurrencyConverter");
        echo "The following properties are available:n";
        print_r($vars);
    
        echo "The method convert() exists for GBPCurrencyConverter: ";
        var_dump(method_exists($gbpConverter, "convert"));
    }
    0 – trả về các thuộc tính mặc định của một lớp
  • <?php
    interface ICurrencyConverter
    {
        public function convert($currency, $amount);
    }
    
    class GBPCurrencyConverter implements ICurrencyConverter
    {
        public $name = "GBPCurrencyConverter";
        public $rates = array("USD" => 0.622846,
                              "AUD" => 0.643478);
        protected $var1;
        private $var2;
    
        function __construct() {}
    
        function convert($currency, $amount) {
            return $rates[$currency] * $amount;
        }
    }
    
    if (interface_exists("ICurrencyConverter")) {
        echo "ICurrencyConverter interface exists.n";
    }
    
    $classes = get_declared_classes();
    echo "The following classes are available:n";
    print_r($classes);
    
    if (in_array("GBPCurrencyConverter", $classes)) {
        print "GBPCurrencyConverter is declared.n";
     
        $gbpConverter = new GBPCurrencyConverter();
    
        $methods = get_class_methods($gbpConverter);
        echo "The following methods are available:n";
        print_r($methods);
    
        $vars = get_class_vars("GBPCurrencyConverter");
        echo "The following properties are available:n";
        print_r($vars);
    
        echo "The method convert() exists for GBPCurrencyConverter: ";
        var_dump(method_exists($gbpConverter, "convert"));
    }
    1 – kiểm tra xem giao diện đã được xác định chưa
  • <?php
    interface ICurrencyConverter
    {
        public function convert($currency, $amount);
    }
    
    class GBPCurrencyConverter implements ICurrencyConverter
    {
        public $name = "GBPCurrencyConverter";
        public $rates = array("USD" => 0.622846,
                              "AUD" => 0.643478);
        protected $var1;
        private $var2;
    
        function __construct() {}
    
        function convert($currency, $amount) {
            return $rates[$currency] * $amount;
        }
    }
    
    if (interface_exists("ICurrencyConverter")) {
        echo "ICurrencyConverter interface exists.n";
    }
    
    $classes = get_declared_classes();
    echo "The following classes are available:n";
    print_r($classes);
    
    if (in_array("GBPCurrencyConverter", $classes)) {
        print "GBPCurrencyConverter is declared.n";
     
        $gbpConverter = new GBPCurrencyConverter();
    
        $methods = get_class_methods($gbpConverter);
        echo "The following methods are available:n";
        print_r($methods);
    
        $vars = get_class_vars("GBPCurrencyConverter");
        echo "The following properties are available:n";
        print_r($vars);
    
        echo "The method convert() exists for GBPCurrencyConverter: ";
        var_dump(method_exists($gbpConverter, "convert"));
    }
    2 – kiểm tra xem một đối tượng có định nghĩa một phương thức hay không
________số 8_______

Đầu ra của đoạn mã trên phải như sau

ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)

Như bạn có thể đoán, phương pháp

<?php
interface ICurrencyConverter
{
    public function convert($currency, $amount);
}

class GBPCurrencyConverter implements ICurrencyConverter
{
    public $name = "GBPCurrencyConverter";
    public $rates = array("USD" => 0.622846,
                          "AUD" => 0.643478);
    protected $var1;
    private $var2;

    function __construct() {}

    function convert($currency, $amount) {
        return $rates[$currency] * $amount;
    }
}

if (interface_exists("ICurrencyConverter")) {
    echo "ICurrencyConverter interface exists.n";
}

$classes = get_declared_classes();
echo "The following classes are available:n";
print_r($classes);

if (in_array("GBPCurrencyConverter", $classes)) {
    print "GBPCurrencyConverter is declared.n";
 
    $gbpConverter = new GBPCurrencyConverter();

    $methods = get_class_methods($gbpConverter);
    echo "The following methods are available:n";
    print_r($methods);

    $vars = get_class_vars("GBPCurrencyConverter");
    echo "The following properties are available:n";
    print_r($vars);

    echo "The method convert() exists for GBPCurrencyConverter: ";
    var_dump(method_exists($gbpConverter, "convert"));
}
1 rất giống với phương pháp class_exists() được thảo luận trong ví dụ đầu tiên. Nó xác định xem giao diện đã cho đã được xác định hay chưa và nhận một đối số chuỗi cho tên giao diện và trình tải tự động tùy chọn Boolean

Phương thức

The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
8 trả về một mảng có tên của tất cả các lớp đã xác định và không nhận đối số. Tùy thuộc vào những thư viện bạn đã tải (tuân thủ PHP hoặc được tải với yêu cầu/bao gồm), các lớp bổ sung có thể xuất hiện

<?php
interface ICurrencyConverter
{
    public function convert($currency, $amount);
}

class GBPCurrencyConverter implements ICurrencyConverter
{
    public $name = "GBPCurrencyConverter";
    public $rates = array("USD" => 0.622846,
                          "AUD" => 0.643478);
    protected $var1;
    private $var2;

    function __construct() {}

    function convert($currency, $amount) {
        return $rates[$currency] * $amount;
    }
}

if (interface_exists("ICurrencyConverter")) {
    echo "ICurrencyConverter interface exists.n";
}

$classes = get_declared_classes();
echo "The following classes are available:n";
print_r($classes);

if (in_array("GBPCurrencyConverter", $classes)) {
    print "GBPCurrencyConverter is declared.n";
 
    $gbpConverter = new GBPCurrencyConverter();

    $methods = get_class_methods($gbpConverter);
    echo "The following methods are available:n";
    print_r($methods);

    $vars = get_class_vars("GBPCurrencyConverter");
    echo "The following properties are available:n";
    print_r($vars);

    echo "The method convert() exists for GBPCurrencyConverter: ";
    var_dump(method_exists($gbpConverter, "convert"));
}
6 lấy một thể hiện đối tượng hoặc một chuỗi làm đối số đại diện cho lớp mong muốn và trả về một mảng các tên phương thức được lớp xác định

Lưu ý rằng từ tất cả các thuộc tính được định nghĩa trong lớp

The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
6 và được trả về bởi phương thức
<?php
interface ICurrencyConverter
{
    public function convert($currency, $amount);
}

class GBPCurrencyConverter implements ICurrencyConverter
{
    public $name = "GBPCurrencyConverter";
    public $rates = array("USD" => 0.622846,
                          "AUD" => 0.643478);
    protected $var1;
    private $var2;

    function __construct() {}

    function convert($currency, $amount) {
        return $rates[$currency] * $amount;
    }
}

if (interface_exists("ICurrencyConverter")) {
    echo "ICurrencyConverter interface exists.n";
}

$classes = get_declared_classes();
echo "The following classes are available:n";
print_r($classes);

if (in_array("GBPCurrencyConverter", $classes)) {
    print "GBPCurrencyConverter is declared.n";
 
    $gbpConverter = new GBPCurrencyConverter();

    $methods = get_class_methods($gbpConverter);
    echo "The following methods are available:n";
    print_r($methods);

    $vars = get_class_vars("GBPCurrencyConverter");
    echo "The following properties are available:n";
    print_r($vars);

    echo "The method convert() exists for GBPCurrencyConverter: ";
    var_dump(method_exists($gbpConverter, "convert"));
}
0, chỉ có
<?php
interface ICurrencyConverter
{
    public function convert($currency, $amount);
}

class GBPCurrencyConverter implements ICurrencyConverter
{
    public $name = "GBPCurrencyConverter";
    public $rates = array("USD" => 0.622846,
                          "AUD" => 0.643478);
    protected $var1;
    private $var2;

    function __construct() {}

    function convert($currency, $amount) {
        return $rates[$currency] * $amount;
    }
}

if (interface_exists("ICurrencyConverter")) {
    echo "ICurrencyConverter interface exists.n";
}

$classes = get_declared_classes();
echo "The following classes are available:n";
print_r($classes);

if (in_array("GBPCurrencyConverter", $classes)) {
    print "GBPCurrencyConverter is declared.n";
 
    $gbpConverter = new GBPCurrencyConverter();

    $methods = get_class_methods($gbpConverter);
    echo "The following methods are available:n";
    print_r($methods);

    $vars = get_class_vars("GBPCurrencyConverter");
    echo "The following properties are available:n";
    print_r($vars);

    echo "The method convert() exists for GBPCurrencyConverter: ";
    var_dump(method_exists($gbpConverter, "convert"));
}
9 và
ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)
0 xuất hiện trong kết quả. Các thuộc tính riêng tư và được bảo vệ đã bị bỏ qua

API phản chiếu PHP

PHP hỗ trợ phản chiếu thông qua API phản chiếu của nó. Như bạn có thể thấy từ hướng dẫn sử dụng PHP, API Reflection hào phóng hơn nhiều so với nội quan và cung cấp một số lượng lớn các lớp và phương thức mà bạn có thể sử dụng để hoàn thành các tác vụ phản chiếu. Lớp

ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)
1 là lớp chính của API và được sử dụng để áp dụng phản ánh trên các lớp, giao diện và phương thức cũng như để trích xuất thông tin về tất cả các thành phần của lớp. Phản chiếu rất dễ triển khai trong mã ứng dụng của bạn và giống như nội quan, cũng rất trực quan

Dưới đây là một ví dụ để minh họa sự phản ánh bằng cách sử dụng các định nghĩa tương tự cho giao diện

The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
6 và các lớp
The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
1 và
The class name is: Introspection
I am a super class for the Child class.
I'm Child class.
I'm Introspection's child.
Yes, Child is a subclass of Introspection.
7

<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}

Đầu ra của đoạn mã trên phải như sau

Child is a subclass of Introspection.
GBPCurrencyConverter implements ICurrencyConverter.
The following methods are available:
Array
(
    [0] => ReflectionMethod Object
        (
            [name] => __construct
            [class] => GBPCurrencyConverter
        )

    [1] => ReflectionMethod Object
        (
            [name] => convert
            [class] => GBPCurrencyConverter
        )

)
The method convert() exists for GBPCurrencyConverter.

Phương thức

ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)
5 trả về một mảng có tên giao diện mà một lớp thực hiện. Phương thức
ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)
6 có thể trả về một đại diện đối tượng
ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)
1 của lớp cha hoặc trả về false nếu không có lớp cha. Để liệt kê tên của đối tượng
ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)
1, bạn sử dụng phương thức
ICurrencyConverter interface exists.
The following classes are available:
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Closure
    [4] => DateTime
    [5] => DateTimeZone
    [6] => DateInterval
    [7] => DatePeriod
    ...
    [154] => GBPCurrencyConverter
)
GBPCurrencyConverter is declared.
The following methods are available:
Array
(
    [0] => __construct
    [1] => convert
)
The following properties are available:
Array
(
    [name] => GBPCurrencyConverter
    [rates] => Array
        (
            [USD] => 0.622846
            [AUD] => 0.643478
        )
)
The method convert() exists for GBPCurrencyConverter: bool(true)
9, như bạn đã thấy trong đoạn mã trên

Phương thức

<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}
0 truy xuất một loạt các phương thức và có thể lấy làm đối số tùy chọn, kết hợp mặt nạ bit của
<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}
1,
<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}
2,
<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}
3,
<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}
4,
<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}
5 và
<?php
$child = new ReflectionClass("Child");
$parent = $child->getParentClass();
echo $child->getName() . " is a subclass of " . $parent->getName() . ".n";

$reflection = new ReflectionClass("GBPCurrencyConverter");
$interfaceNames = $reflection->getInterfaceNames();
if (in_array("ICurrencyConverter", $interfaceNames)) {
    echo "GBPCurrencyConverter implements ICurrencyConverter.n";
}

$methods = $reflection->getMethods();
echo "The following methods are available:n";
print_r($methods);

if ($reflection->hasMethod("convert")) {
    echo "The method convert() exists for GBPCurrencyConverter.n";
}
6 để lọc danh sách dựa trên mức độ hiển thị

Reflection API cung cấp triển khai phản chiếu tốt cho bạn khả năng tạo các ứng dụng phức tạp hơn, chẳng hạn như ApiGen, mặc dù thảo luận thêm nằm ngoài mục tiêu của bài viết này

Tóm lược

Trong bài viết này, bạn đã biết cách sử dụng các hàm nội quan của PHP và API chỉnh sửa để lấy thông tin về các lớp, giao diện, thuộc tính và phương thức. Mục đích của việc lấy thông tin này là để hiểu sâu hơn về mã của bạn trong thời gian chạy và để tạo các ứng dụng phức tạp

Nội quan là gì, giải thích chi tiết bất kỳ hai chức năng nào của nó?

Tự xem xét nội tâm nói chung cung cấp khả năng tiếp cận đặc quyền với trạng thái tinh thần của chính mình, không qua trung gian của các nguồn kiến ​​thức khác, do đó trải nghiệm tâm trí của cá nhân là duy nhất. Introspection can determine any number of mental states including: sensory, bodily, cognitive, emotional and so forth.

Hướng nội trong lập trình là gì?

Khả năng xem xét nội bộ mã là khả năng kiểm tra các lớp, chức năng và từ khóa để biết chúng là gì, chúng làm gì và chúng biết gì . Python cung cấp một số chức năng và tiện ích để xem xét nội tâm mã.

nội quan và tuần tự hóa là gì?

Hướng nội trong PHP. Tính năng nội quan trong PHP cung cấp khả năng hữu ích để kiểm tra các đặc điểm của đối tượng, chẳng hạn như tên, thuộc tính, lớp, giao diện và phương thức của lớp cha (nếu có) . PHP cung cấp một số lượng lớn các chức năng mà bạn có thể sử dụng để hoàn thành nhiệm vụ.

Chức năng của nội quan là gì?

Một cá nhân tự phân tích bản thân và hành vi của mình. Một trong những mục tiêu của việc xem xét nội tâm là để đạt được nhận thức về cảm xúc . Đó là một quá trình mà bạn xem xét tính cách của mình và cách nó tác động đến người khác. Thông qua quá trình này, một người có thể hiểu rõ hơn về quá trình tinh thần của họ.