Remember, when using require that it is a statement, not a function. It's not necessary to write:
<?php
require('somefile.php');
?>
The following:
<?php
require 'somefile.php';
?>
Is preferred, it will prevent your peers from giving you a hard time and a trivial conversation about what require really is.
PHP.mk документација
require
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
function.require.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
function.require.php
require
Референца за `function.require.php` со подобрена типографија и навигација.
require
(PHP 4, PHP 5, PHP 7, PHP 8)
require е идентично со include
освен ако при неуспех, исто така ќе произведе Грешка
исклучок (E_COMPILE_ERROR ниво на грешка пред PHP 8.0.0) додека include ќе произведе само предупредување (E_WARNING ниво на грешка).
Постојат голем број корисни функции за include документација за тоа како функционира ова.
Белешки од корисници 3 белешки
крис на кристоктон точка орг ¶
пред 18 години
Марсел Баур ¶
пред 4 години
If your included file returns a value, you can get it as a result from require(), i.e.
foo.php:
<?php
return "foo";
?>
$bar = require("foo.php");
echo $bar; // equals to "foo"
јаве точка веб на seznam точка cz ¶
пред 2 години
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.