LoginSignup
7
7

More than 5 years have passed since last update.

PHP Warning: The use statement with non-compound nameがでるのはグローバル脳

Posted at

定義されてないインターフェイスやclassでもuseステートメントでの宣言の部分では実際の存在チェックが働かないというのは当たり前なんですが、

<?php
use JsonSerializable;

require 'tests/_autoload.php';
var_dump(new \stdClass instanceof JsonSerializable);

などど書くと、PHP Warning: The use statement with non-compound name 'JsonSerializable' has no effect となってあれれーとなりますけれど、これグローバル名前空間内のためなので、

<?php
namespace Userland {
    require 'tests/_autoload.php';
    use JsonSerializable;

    var_dump(new \stdClass instanceof JsonSerializable);
}

と適当な名前空間内に押し込めれば良い。

まあ、
php
<?php
require 'tests/_autoload.php';
var_dump(new stdClass instanceof \JsonSerializable);

とuse使わなければ、上記エラーはでませんが

7
7
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
7
7