unexpected ‘use’ (T_USE) when trying to use composer

You cannot use “use” where you are using it.

The “use” keyword is either in front of a class definition to import other classes/interfaces/traits into it’s own namespace, or it is inside the class (but not inside a method) to add traits to the class.

namespace Foo;

use Different\Class; // use can go here

class Bar {
  use TraitCode; // use can go here

  public function baz() {
    // use CANNOT go here

Leave a Comment