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

(Php 4> = 4.2.0, Php 5, Php 7, Php 8)

var_export - đầu ra hoặc trả về biểu diễn chuỗi có thể phân tích được của một biếnOutputs or returns a parsable string representation of a variable

Sự mô tả

var_export (hỗn hợp $value, bool $return = false):? chuỗi?(mixed $value, bool $return = false): ?string

var_export () được cấu trúc thông tin về biến đã cho. Nó tương tự như var_dump () với một ngoại lệ: Đại diện được trả về là mã PHP hợp lệ. gets structured information about the given variable. It is similar to var_dump() with one exception: the returned representation is valid PHP code.

Thông số

value

Biến bạn muốn xuất.

________số 8

Nếu được sử dụng và đặt thành true, var_export () sẽ trả về biểu diễn biến thay vì xuất nó.true, var_export() will return the variable representation instead of outputting it.

Trả về giá trị

Trả về biểu diễn biến khi tham số return được sử dụng và đánh giá thành true. Nếu không, chức năng này sẽ trả về

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
2.true. Otherwise, this function will return
(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
2
.

Thay đổi

Phiên bảnSự mô tả
7.3.0 var_export (hỗn hợp $value, bool $return = false):? chuỗi?stdClass objects as an array cast to an object (
(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
3), rather than using the nonexistent method stdClass::__setState(). The practical effect is that now stdClass is exportable, and the resulting code will even work on earlier versions of PHP.

var_export () được cấu trúc thông tin về biến đã cho. Nó tương tự như var_dump () với một ngoại lệ: Đại diện được trả về là mã PHP hợp lệ.

Thông sốvar_export() Examples

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
4

value

array (
  0 => 1,
  1 => 2,
  2 => 
  array (
    0 => 'a',
    1 => 'b',
    2 => 'c',
  ),
)

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
5

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
6

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
7

value

Biến bạn muốn xuất.

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
8

value

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)

Biến bạn muốn xuất.

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
9

value

A::__set_state(array(
   'var' => 5,
))

Biến bạn muốn xuất.

A::__set_state(array(
   'var' => 5,
))
0

A::__set_state(array(
   'var' => 5,
))
1

A::__set_state(array(
   'var' => 5,
))
2

value

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}

Biến bạn muốn xuất.

________số 8:

Nếu được sử dụng và đặt thành true, var_export () sẽ trả về biểu diễn biến thay vì xuất nó.resource couldn't be exported by this function.

________số 8:

Nếu được sử dụng và đặt thành true, var_export () sẽ trả về biểu diễn biến thay vì xuất nó. does not handle circular references as it would be close to impossible to generate parsable PHP code for that. If you want to do something with the full representation of an array or object, use serialize().

Trả về giá trị

Trả về biểu diễn biến khi tham số return được sử dụng và đánh giá thành true. Nếu không, chức năng này sẽ trả về

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
2.var_export() exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility.

________số 8:

Nếu được sử dụng và đặt thành true, var_export () sẽ trả về biểu diễn biến thay vì xuất nó.var_export(), all processed objects must implement the magic __set_state method. The only exception is stdClass, which is exported using an array cast to an object.

Trả về giá trị

  • Trả về biểu diễn biến khi tham số return được sử dụng và đánh giá thành true. Nếu không, chức năng này sẽ trả về
    (object) array(
       'name' => 'ElePHPant ElePHPantsdotter',
       'website' => 'https://php.net/elephpant.php',
    )
    
    2.
  • Thay đổi
  • Phiên bản

Bây giờ xuất các đối tượng STDCLASS dưới dạng mảng được đúc vào một đối tượng (

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
3), thay vì sử dụng phương thức không tồn tại stdClass :: __ setState (). Hiệu ứng thực tế là bây giờ STDClass có thể xuất khẩu và mã kết quả thậm chí sẽ hoạt động trên các phiên bản trước của PHP.

Ví dụ

A::__set_state(array(
   'var' => 5,
))
3

A::__set_state(array(
   'var' => 5,
))
4

A::__set_state(array(
   'var' => 5,
))
5

Bây giờ xuất các đối tượng STDCLASS dưới dạng mảng được đúc vào một đối tượng (

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
3), thay vì sử dụng phương thức không tồn tại stdClass :: __ setState (). Hiệu ứng thực tế là bây giờ STDClass có thể xuất khẩu và mã kết quả thậm chí sẽ hoạt động trên các phiên bản trước của PHP.

Ví dụ

A::__set_state(array(
   'var' => 5,
))
6

Ví dụ #1 var_export () Ví dụ

Ví dụ trên sẽ xuất ra:

A::__set_state(array(
   'var' => 5,
))
7

A::__set_state(array(
   'var' => 5,
))
8

A::__set_state(array(
   'var' => 5,
))
5

Ví dụ #2 Xuất STDClass (kể từ Php 7.3.0)

Ví dụ #3 Lớp xuất

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
0

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
1

A::__set_state(array(
   'var' => 5,
))
5

Ví dụ #4 sử dụng __set_state ()

Ví dụ #3 Lớp xuất

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
3

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
4

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
5

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
6

A::__set_state(array(
   'var' => 5,
))
5

Ví dụ #4 sử dụng __set_state ()

Ghi chú

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
8

object(A)#2 (2) {
  ["var1"]=>
  int(5)
  ["var2"]=>
  string(3) "foo"
}
9

A::__set_state(array(
   'var' => 5,
))
5

Ghi chú:

Ghi chú

$value1

$value2

A::__set_state(array(
   'var' => 5,
))
5

Ghi chú:

Các biến của tài nguyên loại không thể được xuất bởi hàm này.

$value4

$value5

$value6

A::__set_state(array(
   'var' => 5,
))
5

var_export () không xử lý các tham chiếu tròn vì sẽ không thể tạo mã PHP có thể phân tích được cho điều đó. Nếu bạn muốn làm điều gì đó với biểu diễn đầy đủ của một mảng hoặc đối tượng, hãy sử dụng serialize ().

Ghi chú

$value8

$value9

$return0

A::__set_state(array(
   'var' => 5,
))
5

Ghi chú:

Ví dụ

$return2

$return3

$return4

$return5

Ví dụ #1 var_export () Ví dụ

Ví dụ trên sẽ xuất ra:

$return6

$return7

A::__set_state(array(
   'var' => 5,
))
5

Ví dụ #2 Xuất STDClass (kể từ Php 7.3.0)

Ví dụ #3 Lớp xuất

$return9

false0

false1

A::__set_state(array(
   'var' => 5,
))
5

Ví dụ #4 sử dụng __set_state ()

Ghi chú

false3

Ghi chú:

Các biến của tài nguyên loại không thể được xuất bởi hàm này.

false4

false5

false6

false7

false8

false9

value0

value1

value2

value3

A::__set_state(array(
   'var' => 5,
))
5

var_export () không xử lý các tham chiếu tròn vì sẽ không thể tạo mã PHP có thể phân tích được cho điều đó. Nếu bạn muốn làm điều gì đó với biểu diễn đầy đủ của một mảng hoặc đối tượng, hãy sử dụng serialize ().

Ghi chú

value5

value6

A::__set_state(array(
   'var' => 5,
))
5

Ghi chú:

Ví dụ #3 Lớp xuất

value8

value9

return0

return1

return2

return3

A::__set_state(array(
   'var' => 5,
))
5

Ví dụ #4 sử dụng __set_state ()

Các biến của tài nguyên loại không thể được xuất bởi hàm này.

return5

var_export () không xử lý các tham chiếu tròn vì sẽ không thể tạo mã PHP có thể phân tích được cho điều đó. Nếu bạn muốn làm điều gì đó với biểu diễn đầy đủ của một mảng hoặc đối tượng, hãy sử dụng serialize ().

Cảnh báo

return6

return7

return8

return9

true0

true1

true2

A::__set_state(array(
   'var' => 5,
))
5

Ghi chú:

Các biến của tài nguyên loại không thể được xuất bởi hàm này.

true4

false6

false7

false8

false9

true9

value1

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
01

A::__set_state(array(
   'var' => 5,
))
5

var_export () không xử lý các tham chiếu tròn vì sẽ không thể tạo mã PHP có thể phân tích được cho điều đó. Nếu bạn muốn làm điều gì đó với biểu diễn đầy đủ của một mảng hoặc đối tượng, hãy sử dụng serialize ().

Cảnh báo

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
03

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
04

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
05

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
06

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
07

Khi var_export () xuất các đối tượng, dấu gạch chéo ngược hàng đầu không được bao gồm trong tên lớp của các lớp tên để tương thích tối đa.

Các biến của tài nguyên loại không thể được xuất bởi hàm này.

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
08

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
09

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
10

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
11

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
12

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
13

var_export () không xử lý các tham chiếu tròn vì sẽ không thể tạo mã PHP có thể phân tích được cho điều đó. Nếu bạn muốn làm điều gì đó với biểu diễn đầy đủ của một mảng hoặc đối tượng, hãy sử dụng serialize ().

Ví dụ #3 Lớp xuất

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
14

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
15

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
16

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
17

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
18

Ví dụ #4 sử dụng __set_state ()

Ghi chú

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
19

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
20

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
21

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
22

A::__set_state(array(
   'var' => 5,
))
5

Ghi chú:

Các biến của tài nguyên loại không thể được xuất bởi hàm này.

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
24

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
25

A::__set_state(array(
   'var' => 5,
))
5

var_export () không xử lý các tham chiếu tròn vì sẽ không thể tạo mã PHP có thể phân tích được cho điều đó. Nếu bạn muốn làm điều gì đó với biểu diễn đầy đủ của một mảng hoặc đối tượng, hãy sử dụng serialize ().

Các biến của tài nguyên loại không thể được xuất bởi hàm này.

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
27

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
28

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
29

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
30

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
31

A::__set_state(array(
   'var' => 5,
))
5

var_export () không xử lý các tham chiếu tròn vì sẽ không thể tạo mã PHP có thể phân tích được cho điều đó. Nếu bạn muốn làm điều gì đó với biểu diễn đầy đủ của một mảng hoặc đối tượng, hãy sử dụng serialize ().

Ghi chú

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
33

(object) array(
   'name' => 'ElePHPant ElePHPantsdotter',
   'website' => 'https://php.net/elephpant.php',
)
34

A::__set_state(array(
   'var' => 5,
))
5

Làm cách nào để xuất mô -đun PHP?

PHP | ReflectionFunction Export () hàm $ Tên: Đó là hàm được chỉ định sẽ được xuất. $ return: Đó là giá trị boolean đúng hoặc sai. Nếu giá trị của nó được đặt thành đúng thì nó sẽ xuất và nếu giá trị của nó được đặt thành sai thì nó sẽ trả lại null. Sai là giá trị mặc định.ReflectionFunction export() Function $name: It is the specified function which is to be exported. $return: It is the Boolean value either TRUE or FALSE. If its value is set to True then it will export and if its value is set to false then it will return NULL. False is the default value.

Việc sử dụng VAR_ Xuất trong PHP là gì?

Hàm var_export () đầu ra hoặc trả về thông tin có cấu trúc về một biến.Hàm này hoạt động tương tự như var_dump (), ngoại trừ giá trị được trả về cho hàm này là mã PHP hợp lệ.outputs or returns structured information about a variable. This function works similar to var_dump(), except that the returned value for this function is valid PHP code.

Chức năng VAR_DUMP trong PHP là gì?

Hàm var_dump () hủy thông tin về một hoặc nhiều biến.Thông tin giữ loại và giá trị của (các) biến.dumps information about one or more variables. The information holds type and value of the variable(s).

Hàm biến PHP là gì?

Các chức năng biến ¶ PHP hỗ trợ khái niệm các chức năng biến.Điều này có nghĩa là nếu một tên biến có dấu ngoặc đơn được thêm vào nó, PHP sẽ tìm kiếm một hàm có cùng tên với bất kỳ biến nào đánh giá và sẽ cố gắng thực hiện nó.if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it.