|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-03-21 03:18 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2019-03-21 03:18 UTC] requinix@php.net
[2019-03-21 06:07 UTC] xxalfa at gmail dot com
[2019-03-21 22:35 UTC] requinix@php.net
-Status: Not a bug
+Status: Duplicate
[2019-03-21 22:35 UTC] requinix@php.net
[2019-03-21 22:38 UTC] requinix@php.net
[2019-03-21 23:34 UTC] xxalfa at gmail dot com
[2019-03-21 23:39 UTC] requinix@php.net
[2019-03-21 23:42 UTC] spam2 at rhsoft dot net
[2019-03-22 00:55 UTC] xxalfa at gmail dot com
[2019-03-22 01:01 UTC] requinix@php.net
-Block user comment: No
+Block user comment: Yes
[2019-03-22 01:01 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 09:00:01 2025 UTC |
Description: ------------ I don't understand why "goto" is not treated like "require_once"? Test script: --------------- <?php //------------------------------------------------- // HEAD //------------------------------------------------- declare( strict_types = 1 ); header( 'Content-Type:text/plain' ); error_reporting( E_ALL ); ini_set( 'display_errors', '1' ); ini_set( 'html_errors', '0' ); define( 'CORE_DIR', dirname( __FILE__ ) . DIRECTORY_SEPARATOR ); isset( $argv ) or trigger_error( 'This is a command terminal application.', E_USER_ERROR ); echo __FILE__ . ' [PID:' . getmypid() . '][PHP:' . phpversion() . ']' . PHP_EOL . PHP_EOL; function process_recording( $process_message ) { echo 'event ' . $process_message . PHP_EOL; } //------------------------------------------------- // WORKS AS DESIRED //------------------------------------------------- $test = 'foo'; $file_path = CORE_DIR . 'test.php'; // file content: <?php $test = 'bar'; file_exists( $file_path ) and process_recording( 'require_once ' . $file_path ) . ( require_once $file_path ) or process_recording( 'file_not_found ' . $file_path ); echo $test . PHP_EOL; //------------------------------------------------- // DOES NOT WORK AS DESIRED //------------------------------------------------- $action = 2; // Parse error: syntax error, unexpected 'goto' (T_GOTO) // $action === 1 and process_recording( 'goto_action_1' ) . goto goto_action_1; // $action === 2 and process_recording( 'goto_action_2' ) . goto goto_action_2; // $action === 1 and process_recording( 'goto_action_1' ) . ( goto goto_action_1 ); // $action === 2 and process_recording( 'goto_action_2' ) . ( goto goto_action_2 ); // $action === 1 and process_recording( 'goto_action_1' ) . goto( 'goto_action_1' ); // $action === 2 and process_recording( 'goto_action_2' ) . goto( 'goto_action_2' ); //------------------------------------------------- // LOOKS UGLY, BUT WORKS //------------------------------------------------- if ( $action === 1 ): process_recording( 'goto_action_1' ); goto goto_action_1; endif; if ( $action === 2 ): process_recording( 'goto_action_2' ); goto goto_action_2; endif; exit; goto_action_1: echo 'action_1' . PHP_EOL . exit; goto_action_2: echo 'action_2' . PHP_EOL . exit; goto_end_of_file: echo 'end_of_file' . PHP_EOL . exit; ?>