0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AtCoder Programming Guide for beginners(APG4b)をPHPで解く 4章(Exはありません。)

0
Last updated at Posted at 2020-04-21

4.01 include ディレクティブ

include文は指定されたファイルを読み込み、評価する。

※PHPでAtCoderを解く分には使用しない。

4.02 名前空間

名前空間によって、名前の衝突を避けることができる。

名前空間の定義は以下のように行う。

namespace 名前空間名;

名前空間に属する関数を利用する時は、以下のように行う。

名前関数名\関数名;

インポート系シンタックス

requireとrequire_once

requireは指定したファイルを読み込む。
もし、ファイルを読み込めたかった場合は、Fatal Errorを発生する。

require_onceを使用すると、既に読み込まれている場合は再読み込みを行わない。
再読み込みが行われて、変数などが再定義されると困る場合は、require_onceを使う。

includeとinclude_once

includeは、指定したファイルを読み込むという点では、requireと同じ。
ファイルが読み込めなかった場合は、警告を出すのみで、処理は継続する。

include_onceを使用すると、既に読み込まれている場合は再読み込みを行わない。

use

useは、指定した名前空間のクラスを参照できるようにする。
参照したいクラスのnamespaceとクラス名を指定する。
requireやincludeはファイルを指定するのに対して、useはクラス名、名前空間名を指定する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?