たとえば、私は "alpha"と呼ばれる利用可能なオンラインと呼ばれるライブラリを使用していると仮定します。このライブラリにはAuthenticate.phpというファイルがあります。これはライブラリを利用するためにすべてのファイルに含める必要があります。例えばPHPで複数のincludeまたはrequireを使用しないようにするにはどうすればよいですか?
:
for login.php
<?php
include 'Authenticate.php';
include 'Everything.php';
sac::forceAuthentication();
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Authentication Succeeded</h1>
</body></html>
?>
for logout.php
<?php
include 'Authenticate.php';
include 'Everything.php';
sac::logout();
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Logout Successful</h1>
</body></html>
?>
あなたは私がAuthenticate.php
の機能を使用するためにすべての私のファイルにAuthenticate.phpを含める必要が見ることができるように私はこれを行うことを避けることができる方法があります、Everything.phpファイルにAuthenticate.phpを含めることによって?
これを回避するには、次の解決策を考えていました。これが有効な方法であるかどうか教えてください。 Authenticate.phpは、私は必要としない他の多くの機能を持って、私はちょうど使用したい:私は、次の
class Everything {
public function Login(){
include_once('Authenticate.php');
sac::forceAuthentication();
}
public function logout(){
include_once('Authenticate.php');
sac::logout();
}
// Some other functions of everything.php
}
注意をすることによってEverything.phpにAuthenticate.phpの機能を次のものが含ま予定しております
選択された機能とは、Everything.phpに含まれています
ありがとうございます。
これは[PSR-4](http://www.php-fig.org/psr/psr-4/)とオートローダーが存在する理由です。[Composer's autoloader](https://getcomposer.org/ doc/01-basic-usage.md#オートローディング)。 – Sammitch
'php.ini'ファイルの' auto_prepend_file'ディレクティブ – nogad