php / php/php-src

evade `exit_status` overwrite by `exit()`

Aperta
#15,796 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Category: Engine Feature Status: Verified
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con Zend/zend_builtin_functions.c e l'entry point error_reporting esistente, quindi esamina Zend/zend_builtin_functions.stub.php e il Zend/zend_builtin_functions_arginfo.h generato. Determina il workflow supportato per la generazione e il testing di un nuovo builtin exit_status; il lavoro è completato quando la proposta è risolta e lo stato di uscita originale può essere recuperato senza modificare il comportamento di uscita esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, php
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
28/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.