Thông tin có thể được truyền đến các chức năng thông qua danh sách đối số, đây là danh sách các biểu thức được phân phối bằng dấu phẩy. Các đối số được đánh giá từ trái sang phải, trước khi hàm thực sự được gọi (đánh giá háo hức).
PHP hỗ trợ các đối số truyền theo giá trị (mặc định), đi qua tham chiếu và giá trị đối số mặc định. Danh sách đối số có độ dài thay đổi và các đối số được đặt tên cũng được hỗ trợ.
Ví dụ số 1 chuyển mảng cho các chức năng
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
Kể từ Php 8.0.0, danh sách các đối số chức năng có thể bao gồm dấu phẩy kéo dài, sẽ bị bỏ qua. Điều đó đặc biệt hữu ích trong trường hợp danh sách các đối số dài hoặc chứa các tên biến dài, làm cho nó thuận tiện để liệt kê các đối số theo chiều dọc.
Ví dụ #2 Danh sách đối số chức năng với dấu phẩy kéo dài
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
Vượt qua các đối số bằng cách tham khảo
Theo mặc định, các đối số hàm được truyền theo giá trị (để nếu giá trị của đối số trong hàm được thay đổi, nó không bị thay đổi bên ngoài hàm). Để cho phép một hàm sửa đổi các đối số của nó, chúng phải được truyền bằng cách tham chiếu.
Để có một đối số cho một hàm luôn được truyền bởi tham chiếu, hãy trả một ampersand và) cho tên đối số trong định nghĩa chức năng:
Ví dụ #3 Thông số chức năng chuyển qua tham chiếu
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
Đó là một lỗi để truyền một giá trị như là đối số được cho là được thông qua bởi tham chiếu.
Giá trị đối số mặc định
Một hàm có thể xác định các giá trị mặc định cho các đối số bằng cách sử dụng cú pháp tương tự như gán một biến. Mặc định chỉ được sử dụng khi tham số không được chỉ định; Cụ thể, lưu ý rằng việc vượt qua null không gán giá trị mặc định.null does not assign the default value.
Ví dụ #4 Sử dụng các tham số mặc định trong các chức năng
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
Ví dụ trên sẽ xuất ra:
Making a cup of cappuccino. Making a cup of . Making a cup of espresso.
Các giá trị tham số mặc định có thể là các giá trị vô hướng, mảng, loại đặc biệt null và kể từ Php 8.1.0, các đối tượng sử dụng cú pháp ClassName () mới.arrays, the special type null, and as of PHP 8.1.0, objects using the new ClassName() syntax.
Ví dụ #5 Sử dụng các loại không phân chia làm giá trị mặc định
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 1
Ví dụ #6 Sử dụng các đối tượng làm giá trị mặc định (kể từ Php 8.1.0)
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 2
Giá trị mặc định phải là một biểu thức không đổi, không (ví dụ) một biến, thành viên lớp hoặc lệnh gọi hàm.
Lưu ý rằng bất kỳ đối số tùy chọn nên được chỉ định sau bất kỳ đối số bắt buộc nào, nếu không chúng không thể được bỏ qua khỏi các cuộc gọi. Xem xét ví dụ sau:
Ví dụ #7 Sử dụng không chính xác đối số chức năng mặc định
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 3
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 4
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 5Ví dụ trên sẽ xuất ra:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42
Các giá trị tham số mặc định có thể là các giá trị vô hướng, mảng, loại đặc biệt null và kể từ Php 8.1.0, các đối tượng sử dụng cú pháp ClassName () mới.
Ví dụ #5 Sử dụng các loại không phân chia làm giá trị mặc định
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 4
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 8Ví dụ trên sẽ xuất ra:
Making a bowl of raspberry yogurt.
Các giá trị tham số mặc định có thể là các giá trị vô hướng, mảng, loại đặc biệt null và kể từ Php 8.1.0, các đối tượng sử dụng cú pháp ClassName () mới.
Ví dụ #5 Sử dụng các loại không phân chia làm giá trị mặc định
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 9
Making a bowl of raspberry yogurt. 0
Making a bowl of raspberry yogurt. 1Ví dụ trên sẽ xuất ra:
Making a bowl of raspberry natural yogurt.
Các giá trị tham số mặc định có thể là các giá trị vô hướng, mảng, loại đặc biệt null và kể từ Php 8.1.0, các đối tượng sử dụng cú pháp ClassName () mới.null default makes the type implicitly nullable. This usage remains allowed, though it is recommended to use an explicit nullable type instead.
Ví dụ #5 Sử dụng các loại không phân chia làm giá trị mặc định
Making a bowl of raspberry yogurt. 4
Ví dụ #6 Sử dụng các đối tượng làm giá trị mặc định (kể từ Php 8.1.0): As of PHP 7.1.0, omitting a parameter which does not specify a default throws an ArgumentCountError; in previous versions it raised a Warning.
Giá trị mặc định phải là một biểu thức không đổi, không (ví dụ) một biến, thành viên lớp hoặc lệnh gọi hàm.: Arguments that are passed by reference may have a default value.
Lưu ý rằng bất kỳ đối số tùy chọn nên được chỉ định sau bất kỳ đối số bắt buộc nào, nếu không chúng không thể được bỏ qua khỏi các cuộc gọi. Xem xét ví dụ sau:
Ví dụ #7 Sử dụng không chính xác đối số chức năng mặc định
Bây giờ, so sánh những điều trên với điều này:: It is also possible to achieve variable-length arguments by using func_num_args(), func_get_arg(), and func_get_args() functions. This technique is not recommended as it was used prior to the introduction of the Making a bowl of raspberry yogurt. 5 token.
Ví dụ #8 Sử dụng đúng đối số chức năng mặc định
Kể từ Php 8.0.0, các đối số được đặt tên có thể được sử dụng để bỏ qua nhiều tham số tùy chọn.
Making a bowl of raspberry yogurt. 9
Making a bowl of raspberry yogurt. 0
Making a bowl of raspberry natural yogurt. 1Ví dụ trên sẽ xuất ra:
Các giá trị tham số mặc định có thể là các giá trị vô hướng, mảng, loại đặc biệt null và kể từ Php 8.1.0, các đối tượng sử dụng cú pháp ClassName () mới.array or Traversable variable or literal into the argument list:
Ví dụ #5 Sử dụng các loại không phân chia làm giá trị mặc định
Making a bowl of raspberry natural yogurt. 4
Making a bowl of raspberry yogurt. 0
Making a bowl of raspberry natural yogurt. 6Ví dụ trên sẽ xuất ra:
Các giá trị tham số mặc định có thể là các giá trị vô hướng, mảng, loại đặc biệt null và kể từ Php 8.1.0, các đối tượng sử dụng cú pháp ClassName () mới.
Cũng có thể thêm một khai báo loại trước mã thông báo Making a bowl of raspberry yogurt. 5. Nếu điều này có mặt, thì tất cả các đối số được ghi lại bởi Making a bowl of raspberry yogurt. 5 phải khớp với loại tham số đó.
Ví dụ #13 Loại đối số biến được khai báo
3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2 1
Ví dụ trên sẽ xuất ra:
3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2
Cuối cùng, các đối số biến cũng có thể được truyền bằng cách tham chiếu bằng cách tiền tố Making a bowl of raspberry yogurt. 5 với một ampersand và (3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2 3).
Các phiên bản cũ của PHP
Không có cú pháp đặc biệt nào được yêu cầu để lưu ý rằng một hàm là variadic; Tuy nhiên, quyền truy cập vào các đối số của hàm phải sử dụng func_num_args (), func_get_arg () và func_get_args ().func_num_args(), func_get_arg() and func_get_args().
Ví dụ đầu tiên ở trên sẽ được thực hiện như sau trong các phiên bản cũ của PHP:
Ví dụ #14 Truy cập các đối số biến trong các phiên bản PHP cũ
3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2 4
Making a bowl of raspberry yogurt. 0
Making a bowl of raspberry natural yogurt. 1Ví dụ trên sẽ xuất ra:
Cuối cùng, các đối số biến cũng có thể được truyền bằng cách tham chiếu bằng cách tiền tố Making a bowl of raspberry yogurt. 5 với một ampersand và (3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2 3).
Các phiên bản cũ của PHP
Không có cú pháp đặc biệt nào được yêu cầu để lưu ý rằng một hàm là variadic; Tuy nhiên, quyền truy cập vào các đối số của hàm phải sử dụng func_num_args (), func_get_arg () và func_get_args ().
Ví dụ đầu tiên ở trên sẽ được thực hiện như sau trong các phiên bản cũ của PHP:
3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2 7
Ví dụ #14 Truy cập các đối số biến trong các phiên bản PHP cũ
3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2 8
Có tên là đối số
Php 8.0.0 được giới thiệu các đối số được đặt tên là một phần mở rộng của các tham số vị trí hiện có. Các đối số được đặt tên cho phép chuyển các đối số đến một hàm dựa trên tên tham số, thay vì vị trí tham số. Điều này làm cho ý nghĩa của việc tự ghi chép đối số, làm cho các đối số độc lập với thứ tự và cho phép bỏ qua các giá trị mặc định một cách tùy ý.
3 days Catchable fatal error: Argument 2 passed to total_intervals() must be an instance of DateInterval, null given, called in - on line 14 and defined in - on line 2 9
Các đối số được đặt tên được truyền bằng cách tiền tố giá trị với tên tham số theo sau là dấu hai chấm. Sử dụng các từ khóa dành riêng làm tên tham số được cho phép. Tên tham số phải là một định danh, chỉ định động không được phép.
Ví dụ #15 Cú pháp đối số được đặt tên
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
0
Ví dụ #16 Đối số vị trí so với các đối số được đặt tên
Thứ tự mà các đối số có tên được thông qua không quan trọng.
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
1
Ví dụ #17 Ví dụ tương tự như trên với một thứ tự khác nhau của các tham số
Các đối số được đặt tên có thể được kết hợp với các đối số vị trí. Trong trường hợp này, các đối số được đặt tên phải đến sau các đối số vị trí. Cũng có thể chỉ định một số đối số tùy chọn của một hàm, bất kể thứ tự của chúng.
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
2
Ví dụ #18 Kết hợp các đối số được đặt tên với các đối số vị trí ¶
Vượt qua cùng một tham số nhiều lần dẫn đến một ngoại lệ lỗi.
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
3
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
4
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
5
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
6
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
7
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
8
<?php
function takes_array($input)
{
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>
9
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
0
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
1
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?> 2
Ví dụ #19 Lỗi ném khi vượt qua cùng một tham số nhiều lần ¶
Kể từ Php 8.1.0, có thể sử dụng các đối số được đặt tên sau khi giải nén các đối số. Một đối số được đặt tên không được ghi đè một đối số đã được giải nén.
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
3
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
4
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
5
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?> 6
Ví dụ #20 Sử dụng các đối số được đặt tên sau khi giải nén ¶
PHP tại Richardneill Dot org ¶
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
7
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
8
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
9
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 0
7 năm trước ¶
Lilywhite ¶
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
1
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
2
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
3
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
4
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
1 năm trước ¶
Gabriel tại FigDice Dot org ¶
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
6
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
7
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?>
8
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 9
6 năm trước ¶
Boan Dot Web tại Outlook Dot Com ¶
null0
null1
null2
null3
null4
null5
null6
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
4 năm trước ¶
PHP tại Richardneill Dot org ¶
null8
null9
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
7 năm trước ¶
Boan Dot Web tại Outlook Dot Com ¶
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
1
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
2
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
3
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
4
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
5
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
9
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?> 7
4 năm trước ¶
Gabriel tại FigDice Dot org ¶
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
8
<?php
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
9
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
1 năm trước ¶
Gabriel tại FigDice Dot org ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 01
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 02
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
6 năm trước ¶
Boan Dot Web tại Outlook Dot Com ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 04
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 05
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 06
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 07
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 08
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
4 năm trước ¶
Hayley Watson ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 10
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 11
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 125 năm trước ¶
Sergio Santana: Ssantana tại tlaloc dot imta dot mx ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 13
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 14
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 15
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 16
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 17
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 18
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 19
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
16 năm trước ¶
Catman tại esteticas dot se ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 21
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 22
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 23
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 24
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 25JCAPLAN tại Bogus Dot Amazon Dot Com ¶ ¶
Thông tin tại Keraweb dot nl ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 26
Horst Schirmeier ¶ ¶
Kể từ Php 8.1.0, có thể sử dụng các đối số được đặt tên sau khi giải nén các đối số. Một đối số được đặt tên không được ghi đè một đối số đã được giải nén.
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 27
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 28
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
Ví dụ #20 Sử dụng các đối số được đặt tên sau khi giải nén ¶
Lilywhite ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 30
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 31
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 32
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 33
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
1 năm trước ¶
Gabriel tại FigDice Dot org ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 35
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 36
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 37
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 38
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 39
<?phpfunction add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
?> 5
6 năm trước ¶
Boan Dot Web tại Outlook Dot Com ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 41
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 42
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 43
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 444 năm trước ¶
Hayley Watson ¶
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeyogurt(), 1 passed in example.php on line 42 45