note 129162 added to function.require

From: Date: Mon, 15 Jan 2024 14:29:01 +0000
Subject: note 129162 added to function.require
Groups: php.notes 
Request: Send a blank email to php-notes+get-221116@lists.php.net to get a copy of this message
Always use __DIR__ to define path relative to your current __FILE__. (Or another setting that is originally based on __DIR__/__FILE__) try & catch - don't get confused by the words "fatal E_COMPILE_ERROR" - it's still just an internal Error that implements Throwable - it can be caught: <?php try { require(__DIR__ . '/something_that_does_not_exist'); } catch (\Throwable $e) { echo "This was caught: " . $e->getMessage(); } echo " End of script."; ?> Note that this will still emit a warning "Failed to open stream: No such file or directory..." ...unless you prefix the require with "@" - which I strongly don't recommend as it would ignore/supress any diagnostic error (unless you have specified set_error_handler()). But even if you'd prefix the require with "@" it would still be caught. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 2a02:8308:b001:8d00:1741:b40:5d65:cd96) ---- Manual Page -- https://php.net/manual/en/function.require.php Edit -- https://main.php.net/note/edit/129162 Del: integrated -- https://main.php.net/note/delete/129162/integrated Del: useless -- https://main.php.net/note/delete/129162/useless Del: bad code -- https://main.php.net/note/delete/129162/bad+code Del: spam -- https://main.php.net/note/delete/129162/spam Del: non-english -- https://main.php.net/note/delete/129162/non-english Del: in docs -- https://main.php.net/note/delete/129162/in+docs Del: other reasons-- https://main.php.net/note/delete/129162 Reject -- https://main.php.net/note/reject/129162 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221116) next »