Hướng dẫn what is __ function __ in php? - __ function __ trong php là gì?

Hãy để tôi làm rõ nghi ngờ của bạn ..

  • Đầu tiên tôi sẽ giải thích về lớp & đối tượng (sự khác biệt là gì ..)

  • Sau đó, tôi sẽ làm rõ về chức năng & phương pháp (sự khác biệt là gì ..)

Nói về lớp học :: Đó là một triển khai hợp lý của bạn ..

Đối tượng :: Đó là một thể hiện của lớp của bạn (ví dụ ~ sao chép ~ bản sao ~ ...)

Khi bạn đang sử dụng-new-- toán tử ---> bạn đang tạo một đối tượng (không có gì ngoài bản sao) của lớp.

Lớp =============> ~ MỚI ~ ========> Đối tượng (bản sao mới của lớp của bạn ..) Tương tự

Function ==========> ~ MỚI ~ =======> Phương thức (thuộc về đối tượng không phải lớp)

Lớp là chương trình bạn đang viết trong khi đối tượng là bản sao của lớp bạn đang thực hiện ..

lớp cư trú trong ROM (vĩnh viễn) trong đó đối tượng nằm trong RAM (khu vực bộ nhớ tạm thời ..)

& khi bạn khai báo một hàm là tĩnh, nó chỉ thuộc về lớp không phải đối tượng và bạn có thể gọi cùng (hàm tĩnh) bằng cách sử dụng className :: staticFunctionName ()

Đó là lý do tại sao không có sự tồn tại của static_method khá static_function !!!

Mã ví dụ ::

';
    echo __METHOD__ . '
'; echo __FUNCTION__ . '
'; } public function test2() { echo 'Inside NON STATIC function & inside class' . '
'; echo __FUNCTION__ . '
'; echo __METHOD__ . '
'; } } function test() { echo 'Inside NON STATIC function & OUTSIDE class' . '
'; echo __FUNCTION__ . '
'; echo __METHOD__ . '
'; } Dog::name(); test(); $somevar = new Dog; $somevar->test2();

OUTPUT::

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method

Trong trường hợp của bạn khi bạn đang sử dụng phương thức trong bối cảnh tĩnh, nó hiển thị tên lớp nếu nó sẽ không tĩnh (hàm đơn giản), nó sẽ chỉ hiển thị tên hàm chỉ ..METHOD IN static context it showing the class name if the it would be a non static(Simple Function) it would show only function name only..

15 năm trước

Michal Dot Kocarek tại Seznam dot cz ¶

Docey ¶

16 năm trước

Krisj1010 tại gmail.com ¶

Travis Swicegood ¶E_WARNING is emitted. Prior to PHP 8.0.0, no diagnostic was emitted for the magic methods __sleep(), __wakeup(), __serialize(), __unserialize(), and __set_state().

Krisj1010 tại gmail.com ¶

Travis Swicegood ¶

Danillo Dot Paiva Dot Toledo tại Gmail Dot Com ¶

Ricasiano tại Gmail Dot Com ¶ __sleep(): array

1 năm trước __wakeup(): void

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
82 checks if the class has a function with the magic name __sleep(). If so, that function is executed prior to any serialization. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. If the method doesn't return anything then null is serialized and E_NOTICE is issued.

Tom ¶:

__ dòng __ PHP là gì?E_NOTICE level error. Use __serialize() instead.

Việc sử dụng dự định của __s ngủ () là thực hiện dữ liệu đang chờ xử lý hoặc thực hiện các tác vụ dọn dẹp tương tự. Ngoài ra, chức năng này rất hữu ích nếu một đối tượng rất lớn không cần được lưu hoàn toàn.

Ngược lại, unserialize () kiểm tra sự hiện diện của một hàm với tên ma thuật __wakeUp (). Nếu có, chức năng này có thể xây dựng lại bất kỳ tài nguyên nào mà đối tượng có thể có.unserialize() checks for the presence of a function with the magic name __wakeup(). If present, this function can reconstruct any resources that the object may have.

Việc sử dụng dự định của __wakeUp () là thiết lập lại bất kỳ kết nối cơ sở dữ liệu nào có thể bị mất trong quá trình tuần tự hóa và thực hiện các tác vụ tái tạo khác.

Ví dụ #1 giấc ngủ và thức dậy

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
1

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
2

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
3

__Serialize () và __unSerialize ()

public__serialize (): mảng __serialize(): array

public__unSerialize (mảng

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
4): VOID __unserialize(array
Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
4
): void

serialize () kiểm tra xem lớp có hàm với tên ma thuật __serialize (). Nếu vậy, chức năng đó được thực thi trước khi có tuần tự hóa. Nó phải xây dựng và trả về một mảng kết hợp của các cặp khóa/giá trị đại diện cho dạng nối tiếp của đối tượng. Nếu không có mảng nào được trả lại, kiểu mẫu sẽ được ném. checks if the class has a function with the magic name __serialize(). If so, that function is executed prior to any serialization. It must construct and return an associative array of key/value pairs that represent the serialized form of the object. If no array is returned a TypeError will be thrown.

Ghi chú::

Nếu cả __serialize () và __s ngủ () được xác định trong cùng một đối tượng, chỉ __serialize () sẽ được gọi. __S ngủ () sẽ bị bỏ qua. Nếu đối tượng thực hiện giao diện có thể nối tiếp, phương thức

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
5 của giao diện sẽ bị bỏ qua và __serialize () được sử dụng thay thế.

Việc sử dụng dự định của __serialize () là để xác định một biểu diễn tùy ý thân thiện với sê-ri của đối tượng. Các phần tử của mảng có thể tương ứng với các thuộc tính của đối tượng nhưng điều đó không bắt buộc.

Ngược lại, unserialize () kiểm tra sự hiện diện của một hàm với tên ma thuật __unSerialize (). Nếu có, hàm này sẽ được thông qua mảng được khôi phục được trả về từ __serialize (). Sau đó, nó có thể khôi phục các thuộc tính của đối tượng từ mảng đó khi thích hợp.unserialize() checks for the presence of a function with the magic name __unserialize(). If present, this function will be passed the restored array that was returned from __serialize(). It may then restore the properties of the object from that array as appropriate.

Ghi chú::

Nếu cả __serialize () và __s ngủ () được xác định trong cùng một đối tượng, chỉ __serialize () sẽ được gọi. __S ngủ () sẽ bị bỏ qua. Nếu đối tượng thực hiện giao diện có thể nối tiếp, phương thức

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
5 của giao diện sẽ bị bỏ qua và __serialize () được sử dụng thay thế.

Ghi chú::

Nếu cả __serialize () và __s ngủ () được xác định trong cùng một đối tượng, chỉ __serialize () sẽ được gọi. __S ngủ () sẽ bị bỏ qua. Nếu đối tượng thực hiện giao diện có thể nối tiếp, phương thức

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
5 của giao diện sẽ bị bỏ qua và __serialize () được sử dụng thay thế.

Việc sử dụng dự định của __serialize () là để xác định một biểu diễn tùy ý thân thiện với sê-ri của đối tượng. Các phần tử của mảng có thể tương ứng với các thuộc tính của đối tượng nhưng điều đó không bắt buộc.

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
1

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
7

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
8

__toString()

Ngược lại, unserialize () kiểm tra sự hiện diện của một hàm với tên ma thuật __unSerialize (). Nếu có, hàm này sẽ được thông qua mảng được khôi phục được trả về từ __serialize (). Sau đó, nó có thể khôi phục các thuộc tính của đối tượng từ mảng đó khi thích hợp. __toString(): string

Nếu cả __unSerialize () và __wakeUp () được xác định trong cùng một đối tượng, chỉ __unSerialize () sẽ được gọi. __wakeup () sẽ bị bỏ qua.

Tính năng này có sẵn kể từ Php 7.4.0.

Ví dụ #2 sê -ri và unserializestring if possible and if strict typing is disabled.

public__ToString (): ChuỗiStringable interface, and will thus pass type checks for that interface. Explicitly implementing the interface anyway is recommended.

Phương thức __ToString () cho phép một lớp quyết định cách nó sẽ phản ứng khi nó được đối xử như một chuỗi. Ví dụ, những gì

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
9 sẽ in.string, otherwise an Error is thrown.

Cảnh báostring, otherwise a fatal

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
0 is emitted.

Tính năng này có sẵn kể từ Php 7.4.0.

Ví dụ #2 sê -ri và unserialize

public__ToString (): Chuỗi

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
1

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
7

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
3

Phương thức __ToString () cho phép một lớp quyết định cách nó sẽ phản ứng khi nó được đối xử như một chuỗi. Ví dụ, những gì

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
9 sẽ in.

__invoke()

Cảnh báo(

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
4): mixed

Kể từ Php 8.0.0, giá trị trả về theo ngữ nghĩa loại PHP tiêu chuẩn, có nghĩa là nó sẽ được ép thành một chuỗi nếu có thể và nếu việc gõ nghiêm ngặt bị vô hiệu hóa.

Kể từ Php 8.0.0, bất kỳ lớp nào chứa phương thức __tostring () cũng sẽ hoàn toàn thực hiện giao diện có thể chuỗi và do đó sẽ truyền kiểm tra loại cho giao diện đó. Thực hiện rõ ràng giao diện dù sao cũng được khuyến nghị.

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
5

Phương thức __ToString () cho phép một lớp quyết định cách nó sẽ phản ứng khi nó được đối xử như một chuỗi. Ví dụ, những gì

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
9 sẽ in.

Cảnh báo

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
6

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
7

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
8

Phương thức __ToString () cho phép một lớp quyết định cách nó sẽ phản ứng khi nó được đối xử như một chuỗi. Ví dụ, những gì

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
9 sẽ in.

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)

__set_state()

Cảnh báo __set_state(array

Array
(
    [0] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

)
Array
(
    [0] => Array
        (
            [id] => 1
            [first_name] => John
            [last_name] => Do
        )

    [1] => Array
        (
            [id] => 2
            [first_name] => Bob
            [last_name] => Filipe
        )

    [2] => Array
        (
            [id] => 3
            [first_name] => Alice
            [last_name] => Gustav
        )

)
9): object

Kể từ Php 8.0.0, giá trị trả về theo ngữ nghĩa loại PHP tiêu chuẩn, có nghĩa là nó sẽ được ép thành một chuỗi nếu có thể và nếu việc gõ nghiêm ngặt bị vô hiệu hóa.var_export().

Kể từ Php 8.0.0, bất kỳ lớp nào chứa phương thức __tostring () cũng sẽ hoàn toàn thực hiện giao diện có thể chuỗi và do đó sẽ truyền kiểm tra loại cho giao diện đó. Thực hiện rõ ràng giao diện dù sao cũng được khuyến nghị.

Trong Php 7.4, giá trị trả về phải là một chuỗi, nếu không một lỗi được ném.

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
1

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
2

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
3

Phương thức __ToString () cho phép một lớp quyết định cách nó sẽ phản ứng khi nó được đối xử như một chuỗi. Ví dụ, những gì

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
9 sẽ in.

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}

Cảnh báo: When exporting an object, var_export() does not check whether __set_state() is implemented by the object's class, so re-importing objects will result in an Error exception, if __set_state() is not implemented. Particularly, this affects some internal classes. It is the responsibility of the programmer to verify that only objects will be re-imported, whose class implements __set_state().

__debugInfo()

Kể từ Php 8.0.0, giá trị trả về theo ngữ nghĩa loại PHP tiêu chuẩn, có nghĩa là nó sẽ được ép thành một chuỗi nếu có thể và nếu việc gõ nghiêm ngặt bị vô hiệu hóa.(): array

Kể từ Php 8.0.0, bất kỳ lớp nào chứa phương thức __tostring () cũng sẽ hoàn toàn thực hiện giao diện có thể chuỗi và do đó sẽ truyền kiểm tra loại cho giao diện đó. Thực hiện rõ ràng giao diện dù sao cũng được khuyến nghị.var_dump() when dumping an object to get the properties that should be shown. If the method isn't defined on an object, then all public, protected and private properties will be shown.

Trong Php 7.4, giá trị trả về phải là một chuỗi, nếu không một lỗi được ném.

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
4

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
7

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
6

Phương thức __ToString () cho phép một lớp quyết định cách nó sẽ phản ứng khi nó được đối xử như một chuỗi. Ví dụ, những gì

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
9 sẽ in.

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}

Cảnh báo

Kể từ Php 8.0.0, giá trị trả về theo ngữ nghĩa loại PHP tiêu chuẩn, có nghĩa là nó sẽ được ép thành một chuỗi nếu có thể và nếu việc gõ nghiêm ngặt bị vô hiệu hóa.

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
7

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
8

string(60) "A::__set_state(array(
   'var1' => 5,
   'var2' => 'foo',
))"
object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
9

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
0

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
1

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
2

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Kể từ Php 8.0.0, bất kỳ lớp nào chứa phương thức __tostring () cũng sẽ hoàn toàn thực hiện giao diện có thể chuỗi và do đó sẽ truyền kiểm tra loại cho giao diện đó. Thực hiện rõ ràng giao diện dù sao cũng được khuyến nghị.

Trong Php 7.4, giá trị trả về phải là một chuỗi, nếu không một lỗi được ném.

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
4

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
5

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
6

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
7

ctamayo tại sitecraftting dot com

2 năm trước

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
8

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
9

__0

__1

kguest tại php dot net ¶

5 năm trước

__2

__3

__4

__5

jeffxlevy tại gmail dot com

17 năm trước

__6

Smiley tại Hellospambot Dot Chillerlan Dot Net

6 năm trước

__7

__8

__9

public0

Daniel Dot Peder tại Gmail Dot Com ¶

4 năm trước

public1

public2

public3

public4

public5

public6

public7

Rayro ¶

16 năm trước

public8

public9

E_WARNING0

E_WARNING1

E_WARNING2

E_WARNING3

daan dot broekhof tại gmail dot com ¶

10 năm trước

E_WARNING4

E_WARNING5

E_WARNING6

E_WARNING7

E_WARNING8

E_WARNING9

Dhuseby miền getback tld com ¶

14 năm trước

null0

null1

null2

null3

null4

null5

Wesley ¶

11 năm trước

null6

null7

null8

null9

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Martin Dot Goldinger tại NetServer Dot Ch ¶

17 năm trước

E_NOTICE1

E_NOTICE2

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Smiley tại Hellospambot Dot Chillerlan Dot Net

17 năm trước

E_NOTICE4

E_NOTICE5

E_NOTICE6

E_NOTICE7

E_NOTICE8

Smiley tại Hellospambot Dot Chillerlan Dot Net

14 năm trước

E_NOTICE9

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
00

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
01

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
02

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Wesley ¶

11 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
04

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
05

E_NOTICE7

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
07

Martin Dot Goldinger tại NetServer Dot Ch ¶

Ddavenport tại Newagedigital Dot Com ¶

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
08

Yanleech tại Gmail Dot Com ¶

17 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
09

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
10

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Smiley tại Hellospambot Dot Chillerlan Dot Net

10 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
12

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
13

E_NOTICE7

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
15

Dhuseby miền getback tld com ¶

14 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
16

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
17

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
18

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
19

Wesley ¶

11 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
20

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
21

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
22

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
23

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
24

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
25

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
26

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
27

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
28

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
29

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
30

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Dhuseby miền getback tld com ¶

14 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
32

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
33

E_WARNING2

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
35

Wesley ¶

14 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
36

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
37

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
38

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
39

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
40

Wesley ¶

16 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
41

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
42

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
43

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
44

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
45

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
46

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
27

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
48

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
49

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
50

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
51

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
27

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
53

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
54

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
55

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
56

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

daan dot broekhof tại gmail dot com ¶

17 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
58

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
59

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
60

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
61

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Smiley tại Hellospambot Dot Chillerlan Dot Net

11 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
63

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
64

null4

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
66

Martin Dot Goldinger tại NetServer Dot Ch ¶

11 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
67

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
68

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
69

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
70

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
71

object(C)#1 (1) {
  ["propSquared"]=>
  int(1764)
}
3

Martin Dot Goldinger tại NetServer Dot Ch ¶

Ddavenport tại Newagedigital Dot Com ¶

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
73

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
74

E_NOTICE7

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
76

Dhuseby miền getback tld com ¶

14 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
77

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
78

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
79

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
80

E_NOTICE7

Wesley ¶

11 năm trước

14 năm trước

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
83

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
84

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
85

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
86

Inside static function & inside class
Dog::name               //Class::function
name
    
Inside NON STATIC function & OUTSIDE class
test
test
    
Inside NON STATIC function & inside class
test2
Dog::test2            //Object::method
87

__ dòng __ PHP là gì?

__Line__ Số dòng hiện tại của tệp.__File__ đường dẫn đầy đủ và tên tệp của tệp với các liên kết symlink được giải quyết.Nếu được sử dụng bên trong một bao gồm, tên của tệp bao gồm được trả về.The current line number of the file. __FILE__ The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.

__ Tệp __ trong PHP là gì?

__File__ chỉ đơn giản là tên của tệp hiện tại.RealPath (Dirname (__ File__)) có tên của thư mục mà tệp đang ở - về bản chất, thư mục mà ứng dụng được cài đặt.the name of the current file. realpath(dirname(__FILE__)) gets the name of the directory that the file is in -- in essence, the directory that the app is installed in.

__ cuộc gọi () trong PHP là gì?

Phương thức quá tải ¶ __call () được kích hoạt khi gọi các phương thức không thể truy cập trong bối cảnh đối tượng.__callstatic () được kích hoạt khi gọi các phương thức không thể truy cập trong bối cảnh tĩnh.Đối số $ name là tên của phương thức được gọi.triggered when invoking inaccessible methods in an object context. __callStatic() is triggered when invoking inaccessible methods in a static context. The $name argument is the name of the method being called.

__ nhận được gì trong PHP là gì?

Từ hướng dẫn sử dụng PHP: __set () được chạy khi ghi dữ liệu vào các thuộc tính không thể truy cập.__get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập.utilized for reading data from inaccessible properties.