LoginSignup
0
0

More than 1 year has passed since last update.

PHPで名前空間が使われていない古いライブラリを使うときにハマった話

Posted at

クラスがインポートできない

現在phpでは基本的にクラスはオートロードするだろう。
しかし以前はrequire_onceなどを使ってディレクトリで読み込んだりしていたことがあった。もちろん名前空間、それを利用するuse文も使っていなかった。

require_once();

結論

名前空間が使われていないライブラリのクラスの最初の文字に
\ (バックスラッシュ)をつけるだけだ。
どうやらこれでグローバルなクラス?を使えるらしい。
もちろん古いライブラリの使いたいクラスを
require文で読み込んでいることが条件だ。

new somethingClassNameDayo();

こうでおじゃ

new \somethingClassNameDayo() 
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