note 130460 added to function.uopz-allow-exit

From: Date: Tue, 26 Aug 2025 17:31:21 +0000
Subject: note 130460 added to function.uopz-allow-exit
Groups: php.notes 
Request: Send a blank email to php-notes+get-222319@lists.php.net to get a copy of this message
PHP 8.4 changed exit and die to functions, so this call has no effect. Instead you can redefine those functions to do nothing. <?php function allow_exit( bool $allow ) { if ( PHP_VERSION_ID < 80400 ) { uopz_allow_exit( $allow ); } elseif ( $allow ) { uopz_unset_return( 'exit' ); uopz_unset_return( 'die' ); } else { uopz_set_return('exit', static function() {}); uopz_set_return('die', static function() {}); } } ?> Test: <?php echo "Calling die() with allow_exit(false)\n"; allow_exit( false ); die(); echo "Calling die() with allow_exit(true)\n"; allow_exit( true ); die(); echo "Unreachable\n"; ?> Calling die() with allow_exit(false) Calling die() with allow_exit(true) ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.84.18 (proxied: 50.53.121.144) ---- Manual Page -- https://php.net/manual/en/function.uopz-allow-exit.php Edit -- https://main.php.net/note/edit/130460 Del: integrated -- https://main.php.net/note/delete/130460/integrated Del: useless -- https://main.php.net/note/delete/130460/useless Del: bad code -- https://main.php.net/note/delete/130460/bad+code Del: spam -- https://main.php.net/note/delete/130460/spam Del: non-english -- https://main.php.net/note/delete/130460/non-english Del: in docs -- https://main.php.net/note/delete/130460/in+docs Del: other reasons-- https://main.php.net/note/delete/130460 Reject -- https://main.php.net/note/reject/130460 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#222319) next »