php / php/php-src

evade `exit_status` overwrite by `exit()`

Đang mở
#15,796 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Category: Engine Feature Status: Verified
Ngôn ngữ chính
C
Star
40.4k
Fork
8.1k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

as you know there could be multiple exit() occurrences with the help of register_shutdown_function

my case exactly is a shutdown handler that executes once and does exit(), but original exit_status is lost because exit overwrites it. i would like to keep the original exit code. here's some code sample for quick showcase:

register_shutdown_function(function() {
  done(true);# bad termination
});
work();
done();# good termination
###
function work(): void
{
  throw new \Exception('test');# same as exit(255);
  #exit(1001);
}
function done(bool $bad=false): void
{
  static $DID=0;
  if ($DID) {
    return;
  }
  $DID++;
  # ...
  # cleanup
  # ...
  exit($bad ? 1 : 0);
  #exit(exit_status() ?: ($bad ? 1 : 0));# this may save the original
}

to keep behavior the same, i propose to add exit_status() getter similar to error_reporting() that only gets a exit_status value. what you think?

to test those, ive added it right after error_reporting
https://github.com/php/php-src/blob/e358634cdce6a7505b7d422c23ec205a483ad2fc/Zend/zend_builtin_functions.c#L457

ZEND_FUNCTION(exit_status) // {{{
{
	RETURN_LONG(EG(exit_status));
}
// }}}

but also have to add these in https://github.com/php/php-src/blob/master/Zend/zend_builtin_functions_arginfo.h

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_exit_status, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
// ...
ZEND_FUNCTION(exit_status);
// ...
	ZEND_FE(exit_status, arginfo_exit_status)

it has some php file (https://github.com/php/php-src/blob/master/Zend/zend_builtin_functions.stub.php) to generate, i didnt get how to use it

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với Zend/zend_builtin_functions.c và entry point error_reporting hiện có, sau đó kiểm tra Zend/zend_builtin_functions.stub.php và Zend/zend_builtin_functions_arginfo.h được tạo ra. Xác định workflow tạo và kiểm thử được hỗ trợ cho một builtin exit_status mới; được xem là hoàn tất khi đề xuất đã được giải quyết và có thể truy xuất trạng thái thoát ban đầu mà không thay đổi hành vi thoát hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, php
Lĩnh vực
compilers
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.