0

I have this structure:

class MyCollection extends BaseCollection
{

    public function getEntityCLass() : string
    {
        return Item::class;
    }

}

The base collection looks like this:

abstract class BaseCollection {
   public function __construct(array $elements = array())
    {
        foreach ($elements as $entity) {
            $this->add($entity);
        }
    }
}

This makes no sense to me ; getEntityClass should return a string but returns Item::class.

Sending an array to the class works but I honestly don't know why. Anyone care to explain?

1 Answer 1

1

Item::class is a short way of giving a string for the full class, it isn't a method or an object.

For instance.

Instead of Big\Massive\Long\Namespaced\ClassOfSomeSort, so long as you have imported that class with a use statement you can say ClassOfSomeSort::class which will give you the long string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.