Evan Shaw Evan Shaw - 7 months ago 34
PHP Question

What does the 'use' keyword mean in CakePHP 3.x?

I am starting to learn CakePHP, and the use keyword seems to be everywhere, however I can not find documentation for it. Is it like import in Java? Here is an example from the CakePHP blog tutorial.

// src/Model/Table/ArticlesTable.php

namespace App\Model\Table;

use Cake\ORM\Table;

class ArticlesTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Timestamp');
}
}

Answer

It means the same everywhere not just CakePHP.

You are importing a class from another namespace to yours.

Without it you would have to use:

class ArticlesTable extends \Cake\ORM\Table

Instead of the shorter version (Table) you are using.

Comments