Reputation: 21
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');
}
}
Upvotes: 1
Views: 567
Reputation: 4715
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.
Upvotes: 1
Reputation: 13399
The use
keyword gives you the ability to refer to an external fully qualified name with an alias, or importing, is an important feature of namespaces.
All versions of PHP that support namespaces support three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, and aliasing a namespace name. PHP 5.6+ also allows aliasing or importing function and constant names.
Example :
use My\Full\Classname as Another;
For more details check the php documentation
Upvotes: 3