php / php/php-src

evade `exit_status` overwrite by `exit()`

Abierto
#15,796 6 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Category: Engine Feature Status: Verified
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.1k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con Zend/zend_builtin_functions.c y el punto de entrada existente error_reporting; después, inspecciona Zend/zend_builtin_functions.stub.php y el Zend/zend_builtin_functions_arginfo.h generado. Determina el flujo de trabajo admitido para generar y probar un nuevo builtin exit_status; se considera terminado cuando la propuesta está resuelta y se puede recuperar el estado de salida original sin cambiar el comportamiento de salida existente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
c, php
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.